Forums

Losing requests to server somewhere

I see strange things that I cant explain to myself...

So I do several (3+) requests at the same time (1-2 seconds). And those third and above (as I can see) requests do not shows even in "access log". Then some time passes and they appear... It may be 18 second or 206 or something else (especialy those numbers and idk why) according to when the request was sent and when it was taken here.

The problem appeared after some "global world problems" and inability to use the pythonanywhere at all (blocked). Then problem solved itself (idk), but this lag appeared.

How are you making the requests? And what is the response_time showed at the end of the access log lines describing the delayed requests?

How am I making the request is the "problem". It's coming from social networking API. It says in logs that request was sent. So I have to just belive it.

response_time is ok. 0-1 second. I am confused because in API logs it says request was sent. It my logs here it appears only after several time. And then processed as normal request. And I dont know who to belive and what can I do. Or can I even.

Is it possible that the service you're sending requests from has a short timeout set and it disconnects before the request can be handled (an indication of it could be OSError: write error messages in the server log)?

Nope. There is no OSError. I see it in logs sometimes. But it's only one per day or less. And it's something different.

I'm talking about service like Facebook. And as I know it doesnt have any needs it timeout. It just sends me json object on event

The logging is not always immediate, so the request may be handled, but then the log takes some time to be written. In that case, the time of the request shown in the log should still be the original time and it may be out of order with other log messages.

I understand it. But while testing I make logs in my db as well. So, if it handled, it should appear as new row in my table

And the logs in the db don't appear or appear with a delay, as the entries in the access log?

Second case. They appear at the same time.

You have a free account, so your web app can only handle one request at a time. If it is busy with the first request, the others are placed in a queue until the worker for your web app has finished with the first request.

What is this queue? :D

First, problem appeared resently.

Second, yes, i know it. But all requests are handled at 1 or lower seconds. And the delay can be 200+ seconds. How is it queue? Only if on multiple requests my account just stops from receiving requests for some cooldown

Okay, internet lagged and i placed doubled answer...

It's a queue where requests wait until the worker is available. Sometimes, we restart servers. In that case, we have your web app running on a different server, but it may need to start up on the new server. If it takes a while to start up, then you would see that behaviour.

It's not like some rare lag, as I said. It happens every time server gets 2+ requests. May be in 2-3 minutes in a row or something like this.

I may send 3 request and after 1 minute another 3 requests. In this sitiation I will have 2 (from first row) requests handled and 1 lost somewhere. Then will be handled some of the other 3 (more likely 2). THEN come 1 from the first row. It looks just like its stuck somewhere and then being released.

You said that you're logging to the database -- how are you handling the db connection? It could be possible that incorrecly handled connection would be responsible for the behavior you described. You may add more logging to see where your requests are being stuck.

I had logs before connection code. It says something like "Checking connection". And it does not appear too. At some time I placed print in the initiation method, so there is no earlier place to make logs.

db connection is just set. Then on every request I ping it. Recreate if incorrect answer

Since the requests are coming from a social networking API, my guess is that, when you make a number of requests together, one of them times out because the worker is busy. Then the API retries the request later and that is why you see requests made out-of-order - they are being delayed and retried by the API after the first failure.

Fair enough. I still wanna know why It (the problem) appeared it the first place... But I dont think that answer can be found here. Just searching everywhere