Forums

We have 502 error. So sad.

We have one unpleasant problem when working with pythonanywhere we get 502 errors during the day. This problem manifests itself with some frequency.

This manifests itself in the following way: first, the EP freezes and 499 errors appear, then due to the fact that all the workers are hanging on the task, we get 502.

The question is the following, I read in one of the topics that this may be due to a feature of the file system in pythonanywhere. We write logs to a file using logguru. Can this problem be related to writing to a file? and what kind of log recording solution could help us.

With great respect to the entire PAW team, I expect an answer.

There are many things that can cause 502 errors, so we have a help page to help you to identify and fix it: https://help.pythonanywhere.com/pages/502BadGateway/

We've already checked everything. The same thing happens at 45 minutes of every hour, the application seems to freeze. When I try to do something in the console, it does not respond at this time

It sounds like you have something periodically locking some kind of shared resource that all of your code depends on. Are you using a SQLite database, by any chance? That's the most common cause of these kind of locks, because access to it is essentially forced to be single-threaded. The best solution to that specific problem is to switch to MySQL, which is much better at handling multiple concurrent access.

We do not use SQL databases. We made a trace and saw that at this time the time of writing to the log increases from 0.05 seconds to 40-50 seconds. We use logguru for logging. Why can this be and how to treat it?

Could you provide us with some timestamps when this behavior occurs?

Yes, of course. During the load every 15 minutes (15, 30, 45). And the rest of the time in 42 - 46 minutes.

This is how it looks like

This looks like

Thanks for the details! We've looked at our system monitoring, and can't find any periodic slowdowns at times like that. Are you 100% sure that it is the logging that is causing the problem? What happens if you just write to a file using the standard Python functions rather than loguru?

We are no longer sure of anything. Our application freezes at the same time every hour! There are no problems with the database, the only option is that something is happening on your side

The confusing thing is that no-one else is reporting similar problems, and it's hard to imagine a system defect that would cause a hang at the same time every hour for one out of the tens of thousands of accounts we have on our EU system, but would have no impact on any others. That's not to say it's impossible, or that the system is perfect, of course! We could have some weird bug that only shows up under some particular combination of circumstances. But without more information, it's hard for us to see what it could be.

We also notice such a moment that when we run the code through run, we get the following results:

acc: 0.365 token: 0.0 translate: 0.048 confirm: 0.043 rev: 0.042 sendout: 0.042 template: 0.043

and on the stream such:

acc: 3.75 token: 0.0 translate: 0.274 confirm: 0.348 rev: 0.043 sendout: 0.055 template: 0.07

acc is just an aggregate request to MongoDB using pymongo

[edit by admin: formatting]

What additional information do you need? We are ready to collect and provide to solve the problem

Those numbers seem to imply that the MongoDB query is taking longer at certain times, if I understand correctly. Is that right?

Yes, that's right. Through run, the request is made in 0.3 seconds, and in the stream the time can reach up to 5 seconds

Looks like it's time to talk to the database provider and see what's happening on their end.