Api路由被事件循环中的巨大进程阻止
我有一个类似的restify api(我用伪代码写:):
server.post('api/import')
{
database.write(status of this file.id is pending)
fileModification(req.file)
res.status(200)
res.send(import has started)
} //here I do some file modifications and then i import it to database
server.get('api/import_info')
{
database.select(file status)
} //here I want to see status (is file imported or pending(process is not finished yet))
//In another module after import is finished I update database to
database.write(file.id import status is completed)
导入文件的过程大约需要2分钟,但是当我尝试触发“信息”路由时,即使我不等待它在api / import中完成,我的api也被阻止了
是否有可能事件循环被阻塞或连接未正确关闭。
提前感谢
回答如下:我对您的问题有一些想法。
- 您可以使用集群模块 Cluster,集群模块可以根据您的CPU内核创建进程。当进程被阻止时,其他进程仍然可以工作。
- 您可以在api中派生一个新进程,使用新进程处理您的任务。