大约每分钟一次,我需要缓存来自各种加密货币交易所的所有订单簿。有数百个订单簿,因此此更新功能可能永远不会停止运行。
我的问题是:如果我的服务器一直在运行这个订单簿更新功能,它会阻止所有其他服务器功能吗?用户能否与我的服务器交互?
我是否需要创建一个单独的服务来执行更新,或者 Node 能否以某种方式确定 API 请求的优先级并暂停缓存功能?
最佳答案
My question is: If my server is constantly running this orderbook update function, will it block all other server functionality? Will users ever be able to interact with my server?
如果您正在异步编写,这些操作将进入您的事件循环,并且您的 Node 服务器会在执行这些操作时从事件循环中选择下一个事件。如果你有太多这样的事件,你的事件队列会很长,用户会面临非常缓慢的响应,甚至可能会超时
Do I need to create a separate service to perform the updating, or can Node somehow prioritize API requests and pause the caching function?
Node 只使用事件队列中的事件。没有优先级。
从设计的角度来看,您应该寻找可以减少此写入负载的选项,例如 bulkCreate/edit,或者如果您使用 Redis 进行缓存,请考虑 redis pipeline
关于node.js - 服务器不断运行更新缓存的功能,它会阻止所有其他服务器功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50261052/