Forums

Load Balancer error 504

Hi there,

I understand this error from my code is because the request time is taking too long hence it will kill the process. Is there a way I can track line by line on my Django views.py to see which one is taking the most time?

I am not entirely sure since it takes around 5 seconds in my local server but takes forever to run on pythonanywhere.

Thanks! Teng

I am also getting this error as part of trying to deploy the same project:

2021-08-09 07:11:11,296: Not Found: /main.a3f694c0.css
2021-08-09 07:11:11,777: Not Found: /main.41beeca9.js
2021-08-09 07:11:54,504: Not Found: /main.a3f694c0.css
2021-08-09 07:11:54,770: Not Found: /main.41beeca9.js
2021-08-09 07:12:13,759: OSError: write error

Have tried to look around but cannot seem to figure out what this means? Thanks! Teng

The "write error" is likely to be the same problem; when your code does complete, and tries to write the response to the browser, if it has timed out you are likely to get that error.

The easiest way to track down what is taking up the time is to use print statements in your code -- for example, this will write a timestamped message to the server log:

print(f"{datetime.now()}: about to do XXX", flush=True)

...so if you dot a few of those around the slow view, you should be able to track down which line or lines are causing the problem.

Hi Giles,

Thanks for your input! I was able to debug my code further and stumbled upon this error - not sure if there is anything I can do about it:

corrupted size vs. prev_size

Is there any way I can potentially fix this from my end? Thanks! Teng

Could you give more details?

Not entirely sure what the error is ... it just popped up suddenly and it seems to be the one causing a backend 502 error on my website after a while loading:

2021-08-10 12:40:30 E0810 12:40:30.750267     6 analysis_config.cc:81] Please compile with gpu to EnableGpu()
2021-08-10 12:40:30 #033[37m
2021-08-10 12:40:30 ---    Fused 0 subgraphs into layer_norm op.
2021-08-10 12:40:30 #033[0m
2021-08-10 12:40:30 
2021-08-10 12:40:30 E0810 12:40:30.950183     6 analysis_config.cc:81] Please compile with gpu to EnableGpu()
2021-08-10 12:40:30 #033[37m
2021-08-10 12:40:30 ---    Fused 0 subgraphs into layer_norm op.
2021-08-10 12:40:30 #033[0m
2021-08-10 12:40:30 
2021-08-10 12:40:31 [2021/08/10 12:40:31] root INFO: dt_boxes num : 13, elapse : 0.7080140113830566
2021-08-10 12:40:32 [2021/08/10 12:40:32] root INFO: rec_res num  : 13, elapse : 0.4232621192932129
2021-08-10 12:40:32 corrupted size vs. prev_size
2021-08-10 12:47:42 Not Found: /main.a3f694c0.css
2021-08-10 12:47:42 Not Found: /main.41beeca9.js
2021-08-10 12:47:43 Not Found: /main.41beeca9.js
2021-08-10 12:47:43 Not Found: /favicon.ico

What endpoint was hit at 12:40:30? What is it doing?

The endpoint hit was an image being uploaded and submitted and the views.py imports a library that detects texts in the image and draws rectangles / texts in the image. In the above case there are 13 text instances so you see:

2021-08-10 12:40:31 [2021/08/10 12:40:31] root INFO: dt_boxes num : 13, elapse : 0.7080140113830566
2021-08-10 12:40:32 [2021/08/10 12:40:32] root INFO: rec_res num  : 13, elapse : 0.4232621192932129

If that corrupted size vs. prev_size isn't something being printed by your own code, it's probably coming from the library you're using (it's not an error that would come from our system). One possibility that comes to mind is that it could be a concurrency issue. You say that you're processing an uploaded image; is the image always uploaded to the same path? The error message suggests that it might be reading a file and then later finding that it's changed size, so perhaps one person uploads a file, the code starts processing it, and then while it's in the middle of that, another person uploads a different file, causing problems with the ongoing processing.

Thanks! Will look into it further