Totodore / socketioxide

A socket.io server implementation in Rust that integrates with the Tower ecosystem and the Tokio stack.
https://docs.rs/socketioxide
MIT License
1.13k stars 49 forks source link

feat: per client state #330

Closed Totodore closed 1 month ago

Totodore commented 1 month ago

Motivation

Fixes issue:

Currently the global state management is done with a static state. It is convenient because the user can put non clonable data and get a 'static ref from any callback. However this should be completely avoided for the following reasons:

Solution

Thanks to PR #327. It is now possible to access the SocketIo handle from anywhere and therefore the underlying Client instance. You can store the state in the Client instance and access it from anywhere. The main drawback is that a Clone bound is required on the state type provided by the user and it will be cloned each time the user extract it.

Todo:

github-actions[bot] commented 1 month ago

🐰Bencher

ReportThu, June 6, 2024 at 21:00:52 UTC
ProjectSocketioxide
Branchfeat-per-client-state
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

  • Latency (latency)

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns)
engineio_packet/decode/Decode packet binary b64➖ (view plot)87.52
engineio_packet/decode/Decode packet message➖ (view plot)38.89
engineio_packet/decode/Decode packet noop➖ (view plot)35.35
engineio_packet/decode/Decode packet ping/pong➖ (view plot)30.73
engineio_packet/decode/Decode packet ping/pong upgrade➖ (view plot)35.03
engineio_packet/encode/Encode packet binary b64➖ (view plot)56.42
engineio_packet/encode/Encode packet message➖ (view plot)30.68
engineio_packet/encode/Encode packet noop➖ (view plot)29.68
engineio_packet/encode/Encode packet open➖ (view plot)280.63
engineio_packet/encode/Encode packet ping/pong➖ (view plot)29.51
engineio_packet/encode/Encode packet ping/pong upgrade➖ (view plot)29.45
extensions/concurrent_get➖ (view plot)6.81
extensions/concurrent_get_inserts➖ (view plot)15.03
extensions/concurrent_inserts➖ (view plot)21.40
socketio_packet/decode/Decode packet ack on /➖ (view plot)268.56
socketio_packet/decode/Decode packet ack on /custom_nsp➖ (view plot)289.86
socketio_packet/decode/Decode packet binary ack (b64) on /➖ (view plot)478.40
socketio_packet/decode/Decode packet binary ack (b64) on /custom_nsp➖ (view plot)512.42
socketio_packet/decode/Decode packet binary event (b64) on /➖ (view plot)573.07
socketio_packet/decode/Decode packet binary event (b64) on /custom_nsp➖ (view plot)593.38
socketio_packet/decode/Decode packet connect on /➖ (view plot)61.93
socketio_packet/decode/Decode packet connect on /custom_nsp➖ (view plot)79.43
socketio_packet/decode/Decode packet event on /➖ (view plot)346.43
socketio_packet/decode/Decode packet event on /custom_nsp➖ (view plot)358.08
socketio_packet/decode/Decode packet event with ack on /➖ (view plot)341.93
socketio_packet/decode/Decode packet event with ack on /custom_nsp➖ (view plot)358.35
socketio_packet/encode/Encode packet ack on /➖ (view plot)131.14
socketio_packet/encode/Encode packet ack on /custom_nsp➖ (view plot)136.81
socketio_packet/encode/Encode packet binary ack (b64) on /➖ (view plot)320.10
socketio_packet/encode/Encode packet binary ack (b64) on /custom_nsp➖ (view plot)325.89
socketio_packet/encode/Encode packet binary event (b64) on /➖ (view plot)402.97
socketio_packet/encode/Encode packet binary event (b64) on /custom_nsp➖ (view plot)425.26
socketio_packet/encode/Encode packet connect on /➖ (view plot)52.28
socketio_packet/encode/Encode packet connect on /custom_nsp➖ (view plot)56.47
socketio_packet/encode/Encode packet event on /➖ (view plot)133.81
socketio_packet/encode/Encode packet event on /custom_nsp➖ (view plot)138.93
socketio_packet/encode/Encode packet event with ack on /➖ (view plot)131.90
socketio_packet/encode/Encode packet event with ack on /custom_nsp➖ (view plot)138.47

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help