How to handle massive computation on websites? Web workers or CGI?

懵懂的女人 提交于 2019-12-25 08:47:42

问题


I've written a JavaScript-based Website that is able to enter, edit and solve Nonograms. As you may know, solving a nonogram is an NP-complete problem.

My first attempt was pure (single threaded) JavaScript. But on larger nonograms, Chrome showed its BSOD and killed the JS script after a few minutes. Next attempt was to use Web Workers. I split the solving algorithm so that each worker gets one row/column to solve and returns the result. This was an improvement and it was able to solve medium size nonograms. But still, sometimes the browser killed the JS VM showing the BSOD after some time plus the website was not really responsive as I would have expected since this is what Web Workers are made for, aren't they?

Just for "fun", I ported the solving algorithm to Python and used ajax requests calling a python script instead of Web Workers. Interestingly, it was even slower than JavaScript but after a some time of computation, the request returned a 500 Internal Server Error. I believe this is due to the maximum execution time of a CGI script which is 30s on PHP afaik.

The CGI idea was not the best because when multiple users want to solve a nonogram, the server runs on 100% CPU, so I probably stick with client side computation.

So question is, what is the best way to do this computation (which could take like 10min for larger nonograms)? I think the execution time is not an issue as long as the web site stays response and as long as the browser does not kill the execution tasks.

In the meantime, I'm also trying to optimize the recursive algorithm....

Thanks!


回答1:


Maybe you could add some delay before you post messages to the WebWorkers. If the process is split up in to small enough functions, it may be possible to keep the page responsive, though it will take a lot longer to solve.



来源:https://stackoverflow.com/questions/9758999/how-to-handle-massive-computation-on-websites-web-workers-or-cgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!