The R and Python Web Service is a program developed to allow script execution in real-time applications.
There are several web services avalaible for R and Python, but there isn't a solution available for the following requirements:
- The Web Service has to be installed as a Windows Service
- The service has to be self hosted with a simple install\uninstall mode
- The calculation has to support multi core or threads
R and Python code for advanced analytics has latency between milli-seconds and seconds and a single instance cannot scale to hundreds of consumers - Simple end points with only oine GET operation and JSON data input
- Performance metrics such as service and execution latencies
- Minimize client-server latency; the data model should support the push-execute-pull sequence
- Unified data model across different scripting languages; currently these are R, Python and PowerShell(beta)
All commands are executed from the command line in administrative mode:
--install (installs the service)
--uninstall (uninstalls the service)
--cmd (starts the program as a Windows command line app)
In addition, the following software has has to be installed:
R Version 5.2.2, 64bit
Python Version 3.7.2, 64 bit
It is recommended to install both programs under the Windows x64 directory: C:\Program Files\
The service is configured using a JSON file in the install directory named "Analytic.Server.json". The following shows an example:
{
"Port": 8080,
"Address": "http://ServerName",
"Cores": [
{
"Executable": "r.core.exe",
"ExecutablePath": "C:\\Program Files\\Analytic.WebService\\",
"CorePath1": "C:\\Program Files\\R\\R-3.5.2\\bin\\x64",
"CorePath2": "C:\\Program Files\\R\\R-3.5.2",
"WorkingDirectory": "C:/Temp",
"StartUpScripts": [
],
"Cores": 3,
"Language": 1
},
{
"Executable": "python.core.exe",
"ExecutablePath": "C:\\Program Files\\Analytic.WebService\\",
"CorePath1": "C:\\Program Files\\Python\\Python36",
"CorePath2": null,
"WorkingDirectory": "C:/Temp",
"StartUpScripts": null,
"Cores": 3,
"Language": 2
},
{
"Executable": "powershell.core.exe",
"ExecutablePath": "C:\\Program Files\\Analytic.WebService\\",
"CorePath1": null,
"CorePath2": null,
"WorkingDirectory": null,
"StartUpScripts": null,
"Cores": 0,
"Language": 3
}
]
}
The JSON contains both the configuration for the server and the script cores. The server requires to specify both the address and the port. Each core provides the following configuration items:
"Executable" - Name of the core exe
"ExecutablePath" - Installation path of the web service
"CorePath1" - Configuration path; needs to be specified for R
"CorePath2" - Configuration path; needs to be specified for R
"WorkingDirectory" - Working directory for scripts
"StartUpScripts" - List of start-up scripts that need to be executed when the core is initialized
"Cores" - Number of core or threads for calculations
"Language" - Enum specifying the scriping language
The web service displays the Swagger docs:
http://localhost:8080/swagger/ui/index#/Uri
The following data model is used to submit calculations to the web service and retrieve responses.
Value = 0
Vector = 1
Matrix = 2
Frame = 3
None = 0
R = 1
Python = 2
PowerShell = 3
None = 0
Push = 1
Pull = 2
Execute = 3
Information = 4
Error = 5
Stop = 6
None = 0
Double = 1
Int = 2
String = 3
Bool = 4
Frame = 5
double? DoubleValue
int? IntValue
string StringValue
bool? BoolValue
double[] DoubleVector
int[] IntVector
string[] StringVector
bool[] BoolVector
DateTime[] TimeVector
double[,] DoubleMatrix
int[,] IntMatrix
string[,] StringMatrix
bool[,] BoolMatrix
Frame Frame
OperationType Type
ValueType ValueType
Dimension Dimension
string Command
string
string Message
List Operations
double? ServiceTime
double? CoreTime
double? ExecutionTime
LanguageType Language
string UniqueId
string Message
int? QueueLength
string ClientId
string CoreId
The Web service does not require the entire data model for each operation and just a few parameter are needed for basic operations. The main idea is that each calculation can be divided into the following 3 operation types:
- Push; submite data such as bool, int, double or string to the server
- Execute; execute a script or function
- Pull; retrieve results from the server
A simple calculation such as c = a + b can be translated into the following 4 operations:
- Push a
- Push b
- Execute c = a + b
- Pull c
The JSON looks then like this:
