Dash App gives 502 on render

I have a dash app deployed to render. One of the page handles over 1gb of data. I am using polars for it and have two visualizations. But the logs intermittently gives 502 on POST requests when I interact with filters. The app is still interactive but the figures doesn’t update for a couple of minutes and then everything gets back to normal. And the workers are booted again.

Any help regarding this would be great…

The workers are failing, if you are not paying for a render subscription theirs no way it will run. Also look into the workers, increase them if needed or alternatively, cache the data prior to improve the speed.

I am paying for it. I am runnning the largest available Pro Ultra instance for it. I have tried it with autoscaling and even running three Pro Ultra instances is still throwing the same error. Upon further diving in I found that the instances get out of memory and I receive “Your code uses more than 32 gb memory to run” messages in events. Plus I am caching data as well. Tried both local file system and render as cache backend. In case of redis as cache backend I got redis disconnection errors, looks like the instance shuts down and then restarts again that why it gets disconnected with redis.

It can be a bit tricky. The paid render with more capability is a good start.

Hard to specifically point to anything as we dont have any code to view in relation to the project.

Some steps you can take is make the file smaller by changing its file type. Also id assume it isnt solely an initial processing of the file issue. Most likely you have a few events in the code manipluating that data as well which could be the bottle neck.

Find where the majority of the processing is happenings. Add logging at the start, within callbacks and where you think rendering is breaking because of this larger file.

If the issue is with a callback try Background Callbacks | Dash for Python Documentation | Plotly

If the issues is still with a the specific file size consider using a service like:

Also looking through the render forum or reaching out to them could be helpful.

1 Like

Thank you for the detailed reply. The issue seems with callbacks because there is massive computation including joins and groupbys on already massive data. Another thing is that because I am using polars, I have to convert from cached pandas df to polars df for transformation and then again to pandas for visualizations as plotly doesn’t directly support polars. These steps also leads to massive memory consumption. I was thinking about background callbacks myself but just don’t know how to structure them. I have one callback that loads cached pandas df and then converts it into polars df. Then necessary joins, groupby and other transformations and finally a graph and table is updated. I do have multiple Multiselect filters on the top used as inputs of the callback. How do I structure background callbacks in such a case. Any ideas?

This is repo i designed early last week that compared the 3 options, pandas, polars and narwals. You can check out the code and run it to get an idea, their will be a partnered youtube video on the plotly youtube channel in short time so keep an eye out for that.

Its hard for me to offer any dirict advice without understanding the project or code you are workint with.

It can be a little tricky at first but once you find your answers, youll never ask the same question twice lol good luck

1 Like

Thank you for the github repo and I will keep an eye for the youtube video on the plotly channel as well.