Heroka django workers hang on a pole when a customer has a delicate connection

We run the django / gunicorn server on the hero. Most of our users are located in a country where the mobile network is not very large, so often they have scrupulous connections.

Most of our requests are "raw messages" from mobile devices, and it seems that even when the POST request is not completely transmitted, the request is already sent so that it can be processed by the machine gun. When a worker tries to process the request and read the data, it simply freezes, waiting for the remaining data. Although this behavior makes sense for reading files / images in the "streaming" mode, in our case it is pointless because all our messages are relatively small and can be easily read by the web server as a whole and only then redirected to our worker machine gun.

This early handover causes problems when we have many such requests in parallel - because all workers can be blocked. We are currently solving the problem by increasing the number of workers / dinosaurs, but it is quite expensive. I could not find any way to make the web server or puertoric wait and only redirect the request to the employee after it was completely transferred.

Is there a way to make the heroku / gunicorn web server only transmit the request to the machine gun worker when it is completely transmitted from the client side (completely received by the server)?

Sample code (we added a newrelic trace for each statement to make sure this is the exact line that causes the problem):

def syncGameState(request):
    transaction = agent.current_transaction()
    with agent.FunctionTrace(transaction, "syncGameState_raw_post_data", 'Python/EndPoint'):
        data = request.raw_post_data
    with agent.FunctionTrace(transaction, "syncGameState_gameStateSyncRequest", 'Python/EndPoint'):
        sync_request = sync_pb2.gameStateSyncRequest()
    with agent.FunctionTrace(transaction, "syncGameState_ParseFromString", 'Python/EndPoint'):
        sync_request.ParseFromString(data)

Below are the new Relic dimensions for this slow request example (it was POST with 7K data). Reading POST takes 99% of the time of the method ....

enter image description here

+5
2

, , . , ( ) . , - , , - , .

, gevent gunicorn -. IO, , gunicorn - .

gevent gunicorn, gevent (pip install -U gevent) , : gunicorn -k gevent ( , gunicorn gevent ).

0

HTTP- , Waitress.

0

All Articles