简体   繁体   English

Web套接字与间隔轮询

[英]Web Sockets vs Interval Polling

I'm currently looking for the best fitting solution to handle notifications. 我目前正在寻找最合适的解决方案来处理通知。 My current options are either using websockets or just do a polling (only 1 request every minute, no long polling, no permanent polling) 我当前的选择是使用websocket还是只进行轮询(每分钟仅1个请求,不再进行长时间轮询,也不会进行永久轮询)

I somehow have problems to find performance indicators for these methods. 我在某种程度上很难找到这些方法的性能指标。 The result should be able to handle a lot of users in parallel without taking too much resources. 结果应该能够并行处理很多用户,而不会占用太多资源。

Option A: 选项A:

  • Every 30 Seconds a request is sent to check if the users has a new notification 每30秒发送一次请求,以检查用户是否有新通知

Option B: 选项B:

  • Each users holds a websocket connection and is directly informed about a new notification 每个用户都拥有一个websocket连接,并直接收到有关新通知的通知

In the backend i'm using java spring with spring boot. 在后端,我将Java Spring与Spring Boot结合使用。 Do you know any best practices or reference implementations? 您知道任何最佳做法或参考实现吗?

I would suggest to use option A since you just need a quick response and dont want to deliver further information in real time. 我建议使用选项A,因为您只需要快速响应并且不想实时提供更多信息。 You also speak of many users so it should be less resource consuming to request user notifications in a certain timeinterval than keeping an open websocket for each user. 您还会说到许多用户,因此在一定的时间间隔内请求用户通知的资源消耗应比为每个用户保持打开的网络套接字要少。 it also depends on your environment. 这也取决于您的环境。

have also a look here: How many system resources will be held for keeping 1,000,000 websocket open? 还可以看一下: 保持1,000,000个Websocket开放时,将占用多少系统资源?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM