We are currently working on an asynchronous REST API with a priority on performance.

Initially, we wanted to deploy Node.js due to its event-driven architecture, which would fit the use-case nicely, but unfortunately, JavaScript doesn't have support for SCTP sockets yet.

This lead us to Python and after some considerations, we decided to go with uWSGI & gevent.

However, due to the nature of the architecture, there are two areas with significant overhead.

In order to solve the issue of caching data in memory, we use the uWSGI caching framework, which should perform well.

The second issue is that the application connects to a back-end handler through SCTP. With the current setup, this connection will be established and closed for every request. With thousands of requests per second, it leaves a big overhead.

In the ideal case, we would like to establish the socket connection permanently and keep re-using it for each request. In PHP, this is possible with persistent socket connections. Does Python / uWSGI offer a similar feature? Alternatively, we could use the uWSGI queuing framework and process requests in bunches.

Any advice is welcome.

有帮助吗?

解决方案

Once you enable the gevent mode uWSGI became purely (and purely means no monkey-pathing needed) event-driven (otherwise there would be no advantage in using gevent). Gevent means event driven + greenlet (avoiding you to write callback-hell based code like in node.js)

More on the magic here: http://uwsgi-docs.readthedocs.org/en/latest/Async.html

WSGI applications are, well, applications, so if you want to have persistent connections, just open it on server startup or something similar, you do not need special support like in php.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top