1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00
examples/server-sent-events
2020-09-16 01:11:49 +01:00
..
src migrate ci to github actions (#367) 2020-09-16 01:11:49 +01:00
benchmark.js v3 examples (#364) 2020-09-12 16:49:45 +01:00
Cargo.toml v3 examples (#364) 2020-09-12 16:49:45 +01:00
drain.js server-sent events (#177) 2019-09-25 10:39:49 +06:00
README.md server-sent events (#177) 2019-09-25 10:39:49 +06:00

actix-sse

Example of server-sent events, aka EventSource, with actix web.

cargo run

Open http://localhost:8080/ with a browser, then send events with another HTTP client:

curl localhost:8080/broadcast/my_message

my_message should appear in the browser with a timestamp.

Performance

This implementation serve thousand of clients on a 2013 macbook air without problems.

Run benchmark.js to benchmark your own system:

$ 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:

ulimit -n 2048

Test maximum number of open connections with drain.js:

$ node drain.js
Connections dropped: 5957, accepting connections: false^C⏎

Accepting connections indicates wheter resources for the server have been exhausted.