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: io client shared in socketdata #327

Closed Totodore closed 1 month ago

Totodore commented 1 month ago

Motivation

Currently there is no way to access the SocketIo handle from a socket context / handler. The only solution is to store it as a static shared OnceLock in the application code. Having a way to access the SocketIo handle from any context enable two things:

Solution

The chosen solution is to store the SocketIo handle in the engine.io socket data. This allow for any socket to have it set at any time. One other way was to simply propagate the client reference to the handler when events were trigerred. However the main issue with this solution is that when events where trigger from the user side like calling disconnect() on a socket, the use would have to provide the io ref himself.

Todo

github-actions[bot] commented 1 month ago

🐰Bencher

ReportWed, June 5, 2024 at 13:39:04 UTC
ProjectSocketioxide
Branchfeat-io-client-in-socketdata
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.86
engineio_packet/decode/Decode packet message➖ (view plot)38.96
engineio_packet/decode/Decode packet noop➖ (view plot)35.07
engineio_packet/decode/Decode packet ping/pong➖ (view plot)30.85
engineio_packet/decode/Decode packet ping/pong upgrade➖ (view plot)34.99
engineio_packet/encode/Encode packet binary b64➖ (view plot)56.13
engineio_packet/encode/Encode packet message➖ (view plot)30.53
engineio_packet/encode/Encode packet noop➖ (view plot)29.49
engineio_packet/encode/Encode packet open➖ (view plot)288.46
engineio_packet/encode/Encode packet ping/pong➖ (view plot)29.27
engineio_packet/encode/Encode packet ping/pong upgrade➖ (view plot)29.32
extensions/concurrent_get➖ (view plot)6.82
extensions/concurrent_get_inserts➖ (view plot)14.93
extensions/concurrent_inserts➖ (view plot)21.08
socketio_packet/decode/Decode packet ack on /➖ (view plot)268.48
socketio_packet/decode/Decode packet ack on /custom_nsp➖ (view plot)294.92
socketio_packet/decode/Decode packet binary ack (b64) on /➖ (view plot)493.72
socketio_packet/decode/Decode packet binary ack (b64) on /custom_nsp➖ (view plot)525.64
socketio_packet/decode/Decode packet binary event (b64) on /➖ (view plot)575.67
socketio_packet/decode/Decode packet binary event (b64) on /custom_nsp➖ (view plot)599.00
socketio_packet/decode/Decode packet connect on /➖ (view plot)62.51
socketio_packet/decode/Decode packet connect on /custom_nsp➖ (view plot)79.39
socketio_packet/decode/Decode packet event on /➖ (view plot)341.65
socketio_packet/decode/Decode packet event on /custom_nsp➖ (view plot)366.05
socketio_packet/decode/Decode packet event with ack on /➖ (view plot)341.42
socketio_packet/decode/Decode packet event with ack on /custom_nsp➖ (view plot)370.00
socketio_packet/encode/Encode packet ack on /➖ (view plot)116.37
socketio_packet/encode/Encode packet ack on /custom_nsp➖ (view plot)121.30
socketio_packet/encode/Encode packet binary ack (b64) on /➖ (view plot)326.84
socketio_packet/encode/Encode packet binary ack (b64) on /custom_nsp➖ (view plot)331.28
socketio_packet/encode/Encode packet binary event (b64) on /➖ (view plot)403.42
socketio_packet/encode/Encode packet binary event (b64) on /custom_nsp➖ (view plot)428.17
socketio_packet/encode/Encode packet connect on /➖ (view plot)52.09
socketio_packet/encode/Encode packet connect on /custom_nsp➖ (view plot)56.59
socketio_packet/encode/Encode packet event on /➖ (view plot)118.87
socketio_packet/encode/Encode packet event on /custom_nsp➖ (view plot)126.59
socketio_packet/encode/Encode packet event with ack on /➖ (view plot)119.48
socketio_packet/encode/Encode packet event with ack on /custom_nsp➖ (view plot)124.08

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