Forums

HELP ME: "Error code: 504-loadbalancer"

Hi all, I have a web application that can interact with outside service and data. This is just my application for specific purpose, not for normal users. For some reasons, my application takes a big amount of time to run (for few hours). It's my intention because I need statistic data. My local code running OK in eclipse but in PythonAnywhere I meet the problem: "Error code: 504-loadbalancer ". I think it's because the time out of PythonAnywhere. I have an minimum upgraded account (well, the local site don't need a lot of resources to operate), so I wonder is it possible for me to configure timeout for my account?? Appreciate your help. Thank you a lot.

I think the best solution would be to not do the long-running processes from inside your web app. Web app processes are designed to handle lots of short-running requests, and they can in theory be killed and moved around from machine to machine at pretty much any time to load-balance across the network.

A better solution would be to implement the long-running stuff as a scheduled task; then it can run for as long as it wants. This page has some hints on doing it in a fail-safe manner so that it can handle machine outages and that kind of thing.

Hi giles, thanks for your quick response. As I said, the system is just a demonstration and it is acceptable to run a long task. I put my machine run 8hour yesterday to run my application on eclipse to get the result. The idea about scheduled task is good, however it is just not suitable in my context. What I need yo configure a timeout of my web application yo acceptable time (let say 15mins), not just 3mins like it is currently. Can I do thay?

Unfortunately not, the three-minute timeout is a fundamental part of our architecture so we can't change it on a per-web-app basis :-(

Is it any work around solution? Like background services, multiple task... ?

Yes, you can run the background service using a scheduled task -- check out the link in my first post. Why do you think it wouldn't be suitable for your use case?

When I read the code, it look like the separate part, not relate to the web application. For example, if we want to demonstrate your work by web interface, we have to input data via web UI and receive the result. We may not tell audiance that we have the separate component take care the business logic. If the scheduled task is not what I think, and by somehow can integrte with Django web code and return result to the UI. Please help me to explore more about that feature.

The scheduled tasks run in the same environment as the web app -- they have access to all of the same files, and the same databases.

If you're using Django, one neat way to use the same code from a scheduled task as you do in a web app is to create a Django "management command" -- the docs are really good, just google for it. But basically a management command is something you can run from a command line that will have access to all of your models and other code. So you can write one that does the long-running processing and dumps the results to the database, where your web views can read it and display it to the user. You set up the scheduled task to run the management command.

Of course, this doesn't update any web pages that the user already has open. But you can simulate that pretty well by having a little bit of JavaScript in the web pages that hits (say) a Django view that provides the data in JSON format, which you can then update the loaded web page with.

Thanks giles, I will try with your suggestion.

OK -- let me know if you have any comments or questions.