I'm using Laravel5 and, I want to create a notification system for my (web) project. What I want to do is, notifying the user for new notifications such as;
我正在使用Laravel5,我想为我的(web)项目创建一个通知系统。我想做的是,通知用户新的通知,比如;
- another user starts following him,
- 另一个用户开始跟踪他,
- another user writes on his wall,
- 另一个用户在他的墙上写道,
- another user sends him a message, etc,
- 另一个用户给他发信息,等等,
(by possibly highlighting an icon on the header with a drop-down menu. The ones such as *).
(通过使用下拉菜单在标题上突出显示一个图标。像*这样的网站。
I found out the new tutorials on Laracast: Real-time Laravel with Socket.io, where a kind of similar thing is achieved by using Node, Redis and Socket.io.
我找到了Laracast的新教程:带套接字的实时Laravel。io,通过使用Node、Redis和Socket.io实现类似的东西。
If I choose using socket.io and I have 5000 users online, I assume I will have to make 5000 connections, 5000 broadcastings plus the notifications, so it will make a lot of number of requests. And I need to start for every user on login, on the master blade, is that true?
如果我选择使用插座。io和我在网上有5000个用户,我想我将需要5000个连接,5000个广播和通知,所以它会有很多的请求。我需要从每个登录的用户开始,在主刀片服务器上,是这样吗?
Is it a bad way of doing it? I also think same thing can be achieved with Ajax requests. Should I tend to avoid using too many continuous ajax requests?
这是一种不好的做法吗?我还认为Ajax请求也可以实现同样的功能。我应该避免使用太多的连续ajax请求吗?
I want to ask if Socket.io is a good way of logic for creating such system, or is it a better approach to use Ajax requests in 5 seconds instead? Or is there any alternative better way of doing it? Pusher can be an alternative, however, I think free is a better alternative in my case.
我想问一下插座。io是创建这样的系统的一种很好的逻辑方法,还是用5秒的时间来使用Ajax请求更好?或者还有其他更好的方法吗?但是,我认为免费对我来说是更好的选择。
1 个解决方案
#1
3
A few thoughts:
几个想法:
-
Websockets and Socket.io are two different things.
Websockets窝。io是两个不同的东西。
Socket.io might use Websockets and it might fall back to AJAX (among different options).
套接字。io可能使用Websockets,它可能会回归到AJAX(在不同的选项中)。
-
Websockets are more web friendly and resource effective, but they require work as far as coding and setup is concerned.
Websockets更有利于web,更有效地利用资源,但是就编码和设置而言,他们需要工作。
Also using SSL with Websockets for production is quite important for many reasons, and some browsers require that the SSL certificate be valid... So there could be a price to pay.
使用带Websockets生产的SSL也很重要,因为很多原因,一些浏览器要求SSL证书是有效的……所以可能要付出代价。
-
Websockets sometimes fail to connect even when supported by the browser (that's one reason using SSL is recommended)... So writing an AJAX fallback for legacy or connectivity issues, means that the coding of Websockets usually doesn't replace the AJAX code.
即使有浏览器支持,Websockets有时也无法连接(这是使用SSL的一个原因)……因此,为遗留问题或连接性问题编写AJAX回退,意味着Websockets的编码通常不能替代AJAX代码。
-
5000 users at 5 seconds is 1000 new connections and requests per second. Some apps can't handle 1000 requests per second. This shouldn't always be the case, but it is a common enough issue.
5000用户在5秒是1000新的连接和请求每秒。有些应用程序不能每秒处理1000个请求。这不应该总是这样,但这是一个很普遍的问题。
The more users you have, the close your AJAX acts like a DoS attack.
用户越多,AJAX的关闭就像DoS攻击。
On the other hand, Websockets are persistent, no new connections - which is a big resources issue - especially considering TCP/IP's slow start feature (yes, it's a feature, not a bug).
另一方面,Websockets是持久的,没有新的连接——这是一个很大的资源问题——特别是考虑到TCP/IP缓慢的启动特性(是的,它是一个特性,而不是一个bug)。
Existing clients shouldn't experience a DoS even when new clients are refused (server design might effect this issue).
即使拒绝新客户(服务器设计可能会影响这个问题),现有客户也不应该体验DoS。
-
A Heroku dyno should be able to handle 5000 Websocket connections and still have room for more, while still answering regular HTTP requests.
Heroku dyno应该能够处理5000个Websocket连接,并且仍然有空间进行更多的连接,同时仍然能够响应常规的HTTP请求。
On the other hand, I think Heroku imposes an active requests per second and/or backlog limit per dyno (~50 requests each). Meaning that if more than a certain amount of requests are waiting for a first response or for your application to accept the connection, new requests will be refused automatically.... So you have to make sure you have no more than 100 new requests at a time. For 1000 requests per second, you need your concurrency to allows for 100 simultaneous requests at 10ms per request as a minimal performance state... This might be easy on your local machine, but when network latency kicks in it's quite hard to achieve.
另一方面,我认为Heroku每秒钟强加一个活动请求和/或每个dyno(每个请求大约50个)的积压限制。这意味着如果超过一定数量的请求正在等待第一反应或为您的应用程序接受连接,新的请求将被自动拒绝....因此,您必须确保每次不超过100个新请求。对于每秒1000个请求,您需要您的并发性来允许100个同时请求,每个请求10ms,作为最小的性能状态……这在本地机器上可能很容易,但是当网络延迟开始时,就很难实现了。
This means that it's quite likely that a Websocket application running on one Heroku Dyno would require a number of Dynos when using AJAX.
这意味着,在Heroku Dyno上运行的Websocket应用程序在使用AJAX时很可能需要大量的Dynos。
These are just thoughts of things you might consider when choosing your approach, no matter what gem or framework you use to achieve your approach.
当你选择你的方法时,这些只是你可能考虑的事情的想法,不管你用什么宝石或框架来实现你的方法。
Outsourcing parts of your application, such as push notifications, would require other considerations such as scalability management (what resources are you saving on?) vs. price etc'
将应用程序的某些部分(如推送通知)外包出去需要考虑其他因素,比如可伸缩性管理(您节省了哪些资源?)和价格等等。
#1
3
A few thoughts:
几个想法:
-
Websockets and Socket.io are two different things.
Websockets窝。io是两个不同的东西。
Socket.io might use Websockets and it might fall back to AJAX (among different options).
套接字。io可能使用Websockets,它可能会回归到AJAX(在不同的选项中)。
-
Websockets are more web friendly and resource effective, but they require work as far as coding and setup is concerned.
Websockets更有利于web,更有效地利用资源,但是就编码和设置而言,他们需要工作。
Also using SSL with Websockets for production is quite important for many reasons, and some browsers require that the SSL certificate be valid... So there could be a price to pay.
使用带Websockets生产的SSL也很重要,因为很多原因,一些浏览器要求SSL证书是有效的……所以可能要付出代价。
-
Websockets sometimes fail to connect even when supported by the browser (that's one reason using SSL is recommended)... So writing an AJAX fallback for legacy or connectivity issues, means that the coding of Websockets usually doesn't replace the AJAX code.
即使有浏览器支持,Websockets有时也无法连接(这是使用SSL的一个原因)……因此,为遗留问题或连接性问题编写AJAX回退,意味着Websockets的编码通常不能替代AJAX代码。
-
5000 users at 5 seconds is 1000 new connections and requests per second. Some apps can't handle 1000 requests per second. This shouldn't always be the case, but it is a common enough issue.
5000用户在5秒是1000新的连接和请求每秒。有些应用程序不能每秒处理1000个请求。这不应该总是这样,但这是一个很普遍的问题。
The more users you have, the close your AJAX acts like a DoS attack.
用户越多,AJAX的关闭就像DoS攻击。
On the other hand, Websockets are persistent, no new connections - which is a big resources issue - especially considering TCP/IP's slow start feature (yes, it's a feature, not a bug).
另一方面,Websockets是持久的,没有新的连接——这是一个很大的资源问题——特别是考虑到TCP/IP缓慢的启动特性(是的,它是一个特性,而不是一个bug)。
Existing clients shouldn't experience a DoS even when new clients are refused (server design might effect this issue).
即使拒绝新客户(服务器设计可能会影响这个问题),现有客户也不应该体验DoS。
-
A Heroku dyno should be able to handle 5000 Websocket connections and still have room for more, while still answering regular HTTP requests.
Heroku dyno应该能够处理5000个Websocket连接,并且仍然有空间进行更多的连接,同时仍然能够响应常规的HTTP请求。
On the other hand, I think Heroku imposes an active requests per second and/or backlog limit per dyno (~50 requests each). Meaning that if more than a certain amount of requests are waiting for a first response or for your application to accept the connection, new requests will be refused automatically.... So you have to make sure you have no more than 100 new requests at a time. For 1000 requests per second, you need your concurrency to allows for 100 simultaneous requests at 10ms per request as a minimal performance state... This might be easy on your local machine, but when network latency kicks in it's quite hard to achieve.
另一方面,我认为Heroku每秒钟强加一个活动请求和/或每个dyno(每个请求大约50个)的积压限制。这意味着如果超过一定数量的请求正在等待第一反应或为您的应用程序接受连接,新的请求将被自动拒绝....因此,您必须确保每次不超过100个新请求。对于每秒1000个请求,您需要您的并发性来允许100个同时请求,每个请求10ms,作为最小的性能状态……这在本地机器上可能很容易,但是当网络延迟开始时,就很难实现了。
This means that it's quite likely that a Websocket application running on one Heroku Dyno would require a number of Dynos when using AJAX.
这意味着,在Heroku Dyno上运行的Websocket应用程序在使用AJAX时很可能需要大量的Dynos。
These are just thoughts of things you might consider when choosing your approach, no matter what gem or framework you use to achieve your approach.
当你选择你的方法时,这些只是你可能考虑的事情的想法,不管你用什么宝石或框架来实现你的方法。
Outsourcing parts of your application, such as push notifications, would require other considerations such as scalability management (what resources are you saving on?) vs. price etc'
将应用程序的某些部分(如推送通知)外包出去需要考虑其他因素,比如可伸缩性管理(您节省了哪些资源?)和价格等等。