You are here

I develop a solar energy simulation software (Polysun). Controllers can be written as plugins. The SimpleRpcPluginController allows to implement controller logic in other programming languages.

Functions from controlFunctions.py starting with "control_" should be callable from Java.

As shown in article Remote procedure calls to Python using XML-RPC and JSON-RPC with performance comparision standard XML-RPC and standard JSON-RPC show a poor performance for our simulation tool, where Python functions are called more than 100'000 times from Java. The problem is the HTTP protocol where for each request a new TCP connection is created. On Windows, JSON-RPC cannot even be used as the client runs into "java.net.BindException: Address already in use: connect" due to ephemeral TCP ports exhaustion.

I created a new TCP protocol basing on JSON-RPC 2.0, the JSON-RPC stream protocol.

(Optional) Send empty line terminated by EOL to terminate the connection.

EOL = End of line, i.e. \n in Python/Java or Unicode \u000a

It is not anymore JSON-RPC 2.0 compatible as the communication is not over HTTP.

Measurements

Measured average time per function call for contro_flowrate() in Python and FlowratePluginController in Java 8 (Eclipse debug) on a Intel Core i7-4500U CPU 1.80GHz (dual core) for more than 100'000 function calls on localhost are about:

JSON-RPC stream

JSON-RPC

XML-RPC

Java

Matlab

RPC type:

custom

standard

standard

native

library

Communication protocol:

TCP socket

HTTP

HTTP

native

RMI

TCP connection per

simulation

timestep

timestep

N/A

simulation

PyPy 5.4.1, Java non-debug

0.06ms

0.3ms

0.6ms

0ms

0.6ms

PyPy 5.4.1

0.06ms

0.5ms

0.9ms

0ms

0.6ms

Python 2.7

0.09ms

0.7ms

1.3ms

0ms

0.6ms

Python 3.4

0.08ms

0.9ms

1.4ms

0ms

0.6ms

Jython 2.7.0

(20ms)

Performance factors comparing for the same Python interpreter (e.g JSON-RPC using pypy needs five times (500%) more time than JSON-RPC stream):

The JSON-RPC stream protocol on pypy is five times faster (500%!) than the standard JSON-RPC HTTP-based RPC protocol on pypy.
The JSON-RPC stream on pypy is 23 times (2300%!) faster than the XML-RPC on python 3.4.

This function is called more than 100'000 times from Java code.

On the Java side a TCP socket and parts of JSON-RPC for JSON-RPC function wrapping are used.