I've started tinkering with Node.js HTTP server and really like to write server side Javascript but something is keeping me from starting to use Node.js for my web application.(我已经开始修补Node.js HTTP服务器,并且非常喜欢编写服务器端Javascript,但有些东西阻止我开始使用Node.js作为我的Web应用程序。)
I understand the whole async I/O concept but I'm somewhat concerned about the edge cases where procedural code is very CPU intensive such as image manipulation or sorting large data sets.(我理解整个异步I / O概念,但我有点担心程序代码非常CPU密集的边缘情况,例如图像处理或排序大数据集。) As I understand it, the server will be very fast for simple web page requests such as viewing a listing of users or viewing a blog post.(据我了解,服务器对于简单的网页请求非常快,例如查看用户列表或查看博客帖子。) However, if I want to write very CPU intensive code (in the admin back end for example) that generates graphics or resizes thousands of images, the request will be very slow (a few seconds).(但是,如果我想编写非常CPU密集型代码(例如在管理员后端)生成图形或调整数千个图像的大小,请求将非常慢(几秒钟)。) Since this code is not async, every requests coming to the server during those few seconds will be blocked until my slow request is done.(由于此代码不是异步的,因此在几秒钟内发送到服务器的每个请求都将被阻止,直到我的慢请求完成为止。) One suggestion was to use Web Workers for CPU intensive tasks.(一个建议是使用Web Workers进行CPU密集型任务。) However, I'm afraid web workers will make it hard to write clean code since it works by including a separate JS file.(但是,我担心网络工作者会很难编写干净的代码,因为它的工作方式是包含一个单独的JS文件。) What if the CPU intensive code is located in an object's method?(如果CPU密集型代码位于对象的方法中该怎么办?) It kind of sucks to write a JS file for every method that is CPU intensive.(为每个CPU密集型方法编写一个JS文件真是太糟糕了。) Another suggestion was to spawn a child process, but that makes the code even less maintainable.(另一个建议是生成子进程,但这使得代码更难以维护。) Any suggestions to overcome this (perceived) obstacle?(有什么建议可以克服这个(感知的)障碍吗?) How do you write clean object oriented code with Node.js while making sure CPU heavy tasks are executed async?(如何使用Node.js编写干净的面向对象代码,同时确保CPU重任务执行异步?) ask by Olivier Lalonde translate from so