1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00
examples/server-sent-events
2024-07-07 00:23:03 +01:00
..
src refactor: use graduated Html responder 2024-07-07 00:23:03 +01:00
benchmark.js use semantic SSE types 2022-08-07 01:24:40 +01:00
Cargo.toml update actix ecosystem deps 2023-10-29 01:06:58 +01:00
drain.js fix server-sent-events/drain.js (#615) 2023-03-30 03:57:54 +01:00
README.md change curl -X post to curl -X POST (#614) 2023-03-30 03:46:10 +01:00

actix-sse

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

cd server-sent-events
cargo run

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

curl -X POST 127.0.0.1:8080/broadcast/my_message

my_message should appear in the browser with a timestamp.

Performance

This implementation can serve thousands of clients on a 2021 MacBook with no problems.

Run node ./benchmark.js to benchmark your own system:

$ node benchmark.js
Connected: 1000, connection time: 201 ms, total broadcast time: 20 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 node ./drain.js:

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

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