Skip to content

rosisoft/R-and-Python-Web-Service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

R-and-Python-Web-Service

The R and Python Web Service is a program developed to allow script execution in real-time applications.

Introduction

There are several web services avalaible for R and Python, but there isn't a solution available for the following requirements:

  1. The Web Service has to be installed as a Windows Service
  2. The service has to be self hosted with a simple install\uninstall mode
  3. 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
  4. Simple end points with only oine GET operation and JSON data input
  5. Performance metrics such as service and execution latencies
  6. Minimize client-server latency; the data model should support the push-execute-pull sequence
  7. Unified data model across different scripting languages; currently these are R, Python and PowerShell(beta)

Installation

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\

Configuration

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

Swagger Docs

The web service displays the Swagger docs:

http://localhost:8080/swagger/ui/index#/Uri

JSON Data Model

The following data model is used to submit calculations to the web service and retrieve responses.

Dimension

Value = 0
Vector = 1
Matrix = 2
Frame = 3

LanguageType

None = 0
R = 1
Python = 2
PowerShell = 3

OperationType

None = 0
Push = 1
Pull = 2
Execute = 3
Information = 4
Error = 5
Stop = 6

ValueType

None = 0
Double = 1
Int = 2
String = 3
Bool = 4
Frame = 5

Operation

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

Sequence

List Operations
double? ServiceTime
double? CoreTime
double? ExecutionTime
LanguageType Language
string UniqueId
string Message
int? QueueLength
string ClientId
string CoreId

Quick Start

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:

http://ServerName:8080/api/language/r?json={Operations:[{Type:1,DoubleValue:1,Name:a},{Type:1,DoubleValue:2,Name:b},{Type:3,Command:c=sum(a,b)},{Type:2,Dimension:0,ValueType:1,Name:c}],Language:1}

About

R and Python Web Service is a program developed to allow real-time caclulations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors