Benchmark RPC Systems (and Inverted Json)



Comparison of various tools (RabbitMQ, Crossbar.io, Nats.io, Nginx, etc.) for organizing RPC between microservices.



Memory usage




CPU usage




Multi processor test




1. Tests



All tools are divided into 3 groups:

Some thoughts on the benchmark below.



2. MQ or RPC



Although these 2 communication methods are different, sometimes the first is used instead of the second and vice versa.

If you try to outline the boundaries, when to use what, you can get something like this:



3. RPC over RabbitMQ



RabbitMQ is often used to organize RPCs, but like similar MQ systems it creates an additional overhead, which is why its use is not very productive.



If you use the “queue” for RPC, then you need to clean the channels, because if the worker has fallen for a while, then after restarting it can get a bunch of irrelevant tasks, because clients sent requests all this time and, in addition, waited in vain for an answer. the worker was not active. In total, the worker will receive the task even if the client has left before, the same with the client, if the client’s channel is not counted, then he may get clogged with unaccepted answers from the worker, although in RabbitMQ you can close the client channel, but at the same time performance drops dramatically.



You also need to do a pork worker to know if he is alive.

In addition, resources are spent on working with channels, when in RPC systems data is simply sent to the worker and vice versa.



4. Inverted Json



There are many different MQ systems, but not many Job servers (RPCs) such as Gearman / Crossbar.io are very small choices, so developers often take MQ systems for RPCs.

Therefore, Inverted JSON (iJson) was created - a proxy server with an http interface where clients and workers connect as a network client: [client] -> [Inverted Json] <- [worker], written in C / C ++, uses epoll, state machines for routing, json streaming parser, slices instead of strings *, etc. methods for better performance.



Advantages of Inverted JSON over RabbitMQ:



Other Inverted Json Information





5. Try Inverted Json in 3 minutes



You can try Inverted Json right now if you have Docker and curl :





Description from the picture:

1) Running the docker image of Inverted Json on port 80 (you can choose any), --log 32 logs incoming requests:

$ docker run -it -p 80:8001 lega911/ijson --log 32
      
      





2) We register the worker for the “calc / sum” task, and wait for the task:

 $ curl localhost/rpc/add -d '{"name": "calc/sum"}'
      
      





3) The client makes an RPC request calc / sum:

 $ curl localhost/calc/sum -d '{"id": 15, "data": "2+3"}'
      
      





4) The worker receives the task `{" id ": 15," data ":" 2 + 3 "}` - the data is unchanged, now you need to send the result to the same id:

 $ curl localhost/rpc/result -d '{"id": 15, "result": 5}'
      
      





... and the client gets the result as it is `{"id": 15, "result": 5}`







5.1. Jsonrpc



JsonRPC 2 is not supported, but there are some rudiments, for example, the client can send requests like (url / rpc / call):

 {"jsonrpc": "2.0", "method": "calc/sum", "params": [42, 23], "id": 1}
      
      



accept errors like:

 {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": null}
      
      



However, if there is demand, then JsonRPC support can be improved.



5.2. Python client and worker example



 # client.py import requests print(requests.post('http://127.0.0.1:8001/test/command', json={'id': 1, 'params': 'Hello'}).json()) # worker.py import requests while True: request = requests.post('http://127.0.0.1:8001/rpc/add', json={'name': '/test/command'}).json() response = { 'id': request['id'], 'result': request['params'] + ' world!' } requests.post('http://127.0.0.1:8001/rpc/result', json=response)
      
      





And here you can find an example in the "worker mode", which is more productive and compact.



6. Some thoughts on the benchmark result







7. Conclusion



If you have a large company and many employees, then you can afford to support various complex tools for organizing direct connections between microservices, which can provide effective communication.

And for small companies and startups, where a small team needs to solve problems from various fields, Inverted Json can save time and resources.



For the development of Inverted Json, plans include support for pubsub, kubernetes, and other interesting ideas.

If you are interested in the project or just want to help the author, you can put an asterisk on the github project , thanks.



PS:






All Articles