当前正在Standard-1X
使用Node,Express和Socket.io构建一个运行Heroku dyno的项目。该应用程序的前提非常简单:人们从客户端搜索商品(像Dicts一样存储在引擎盖下):
['Item':'Coffee',
'Id':0247508725,
'Location': 'Baker Street']
并选择它们,然后将项目键值推送到节点服务器并存储在列表中。然后,其余客户端“实时”检索该列表。客户端都是本机构建的Swift iOS应用
我第一次与大约60个用户一起运行,所有用户都同时搜索和添加项目。Heroku仪表板的结果令人震惊:
I thought I had been thorough in testing, I had never seen so many H12 & H13 errors. Part of me thinks it might be inefficient code on my server side, or simply the lack of proper Node implementation to handle so many requests so I'm not constantly waiting on I/O because of the whole single threaded-ness deal.
Here is an example of the function server side that runs to add an item on that list:
clientSocket.on("additionToList", function(Location,Item,Id){
client.query("INSERT q_venue_list (item_name, item_id, at_location) VALUES ($1, $2, $3)",[Item,Id,Location], function(err, result) {
if(err) {
return console.error('error running insert', err);
}
io.sockets.in(Location).emit('updateList');
});
});
When the clients sockets in room Location
receive the 'updateList'
command, they pull the new list. Storage and retrieval all work fine, but for some reason with all these people, everything got bogged down and was extremely lagged. I hardly know what I'm doing but I'm just trying to understand where I might be going wrong. I can't cluster because I only get access to one core, so would be next best option be to explore async? Could it be horrible device signal, coupled with waiting on I/O that causes all the timeouts?
I'm just looking to understand this, any help is appreciated. Let me know if I can provide more information.
对于遇到这种奇怪问题的任何人,我最终都弄清楚了问题所在。我没有释放套接字层并没有断开或socket.disconnect
上的()的连接。这导致后端上的该套接字等待直到超时(55秒)。在等待的整个过程中,它一直困扰着事件循环的其余部分。因此,其他传入请求将等待,然后它们也将超时。applicationDidEnterBackground
applicationWillResignActive
tl; dr:努力打开和关闭插槽。用户退出应用程序时,请不要忘记关闭它们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句