2019-09-25 06:39:49 +02:00
|
|
|
# actix-sse
|
|
|
|
Example of server-sent events, aka `EventSource`, with actix web.
|
|
|
|
|
|
|
|
```sh
|
2021-10-06 23:28:53 +02:00
|
|
|
cd other/server-sent-events
|
2019-09-25 06:39:49 +02:00
|
|
|
cargo run
|
|
|
|
```
|
|
|
|
|
|
|
|
Open http://localhost:8080/ with a browser, then send events with another HTTP client:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
curl localhost:8080/broadcast/my_message
|
|
|
|
```
|
|
|
|
|
|
|
|
*my_message* should appear in the browser with a timestamp.
|
|
|
|
|
|
|
|
## Performance
|
2021-10-06 23:28:53 +02:00
|
|
|
This implementation serve thousands of clients on a 2013 macbook air without problems.
|
2019-09-25 06:39:49 +02:00
|
|
|
|
|
|
|
Run [benchmark.js](benchmark.js) to benchmark your own system:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ node benchmark.js
|
|
|
|
Connected: 1000, connection time: 867 ms, total broadcast time: 23 ms^C⏎
|
|
|
|
```
|
|
|
|
|
|
|
|
### Error *Too many open files*
|
|
|
|
You may be limited to a maximal number of connections (open file descriptors). Setting maximum number of open file descriptors to 2048:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
ulimit -n 2048
|
|
|
|
```
|
|
|
|
|
|
|
|
Test maximum number of open connections with [drain.js](drain.js):
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ node drain.js
|
|
|
|
Connections dropped: 5957, accepting connections: false^C⏎
|
|
|
|
```
|
|
|
|
|
2021-10-06 23:28:53 +02:00
|
|
|
_Accepting connections_ indicates whether resources for the server have been exhausted.
|