Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: per client state #330

Merged
merged 40 commits into from
Jun 7, 2024
Merged

feat: per client state #330

merged 40 commits into from
Jun 7, 2024

Conversation

Totodore
Copy link
Owner

@Totodore Totodore commented Jun 5, 2024

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:

  • With multiple clients spawned, they are going to share the same state and this will probably lead to bugs. First example with all the integration tests for the socketioxide lib.
  • Currently the implementation uses unsafe code to do this. Moving to a per client clonable state remove this.
  • This will lead to a possible axum-like state implementation. Having only one typed state rather than the type erased typemap.

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:

  • Update examples to add clone bounds and take state by value
  • Improve documentation

@Totodore Totodore added the bug Something isn't working label Jun 5, 2024
@Totodore Totodore linked an issue Jun 5, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Jun 5, 2024

🐰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

socketioxide/src/io.rs Fixed Show fixed Hide fixed
socketioxide/src/io.rs Fixed Show fixed Hide fixed
socketioxide/src/io.rs Fixed Show fixed Hide fixed
socketioxide/src/io.rs Fixed Show fixed Hide fixed
@Totodore Totodore merged commit 3bb916e into main Jun 7, 2024
13 checks passed
@Totodore Totodore deleted the feat-per-client-state branch June 7, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hold a per Client state rather than a static state.
1 participant