开发者

How to stop Apache from freezing up when multiple requests are sent to django views that output Matplotlib images?

I have a django site that servers ma开发者_Go百科tplotlib images generated from numbers stored in a mysql database.

One of the views will display up to 5 images. The src value for the images do not link to static files but instead to django views that will generate png images. The images can take up to 5 seconds to load. The same django view function is not being called repeatedly. The five images correspond to different types of plotting methods, each has its own function in django view.

When multiple requests for the images are sent, the server freezes up. I am developing the site with xampp. I cannot load the site in another tab, or any of the php sites I have running on the same server.

If I try to load all the images with the initial page load the server freezes. If I load the page then request the images separately using jquery/ajax (and wait patiently) then there is no problem. If I quickly make two ajax requests then the server freezes.

Can anyone explain what might be the source of the problem?

Can I force the serialized execution of the requests on the server?

Can I use javascript to delay each request until the prior image is returned (and not just when the link is update as is currently the case)?

Or can I put a time limit on the requests to kill these hang ups on the server?

Thanks. It would be a big help if someone could help me resolve this.


You could use a two stage process to generate these pages:

  • On the initial request, push the image generation tasks into a queuing system such as celery. Use a separate process to execute these tasks, and tune it to run as many as your system will cope with in parallel.
  • On the client side, use ajax to poll the server to determine when the image generation tasks are complete, and finalise the display.


Are you serving your images with apache? if that so you could try a lighter server for your media like nginx, lighttpd, TUX, Cherokee or even a A stripped-down version of Apache.

to be able to do this you could save your image in a tmp directory and serve it there if you do not wish to save the image.

You can see some extended documentation on https://docs.djangoproject.com/en/dev/howto/static-files/

The problem i think its happening is that apache stays serving media (heavy media) and you get out of open connections. There is when a lighter server can help since its able to manage a lot more connections than apache could.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜