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: namespace routing #333

Merged
merged 65 commits into from
Jun 25, 2024
Merged

feat: namespace routing #333

merged 65 commits into from
Jun 25, 2024

Conversation

Totodore
Copy link
Owner

@Totodore Totodore commented Jun 7, 2024

Motivation

Adding Namespace routing would allow to add a layer of multiplexing and also match the features of the official socket.io client.

Close issue #212.

Solution

Because I think that a regex based solution is way to slow and overkill for a simple router feature, the routing is implemented using the matchit crate. This allow to have a simple syntax for path parameters: /admin/{id}/board and even wildcards /admin/{*path}.
One of the main drawbacks is the need of an adjacent buffer to store namespace because it is not possible to iterate over the path /values of the router. So currently this is using the slab crate from tokio to store namespace and the router only stores indexes.

Performance

Here are some benchmark results to compare previous Hashmap based implementation with the new based on Router + Slab:
image

Todo

  • Provide an extractor for the connect handler to get path parameters
  • Update tests and examples
  • Update documentation

@Totodore Totodore marked this pull request as ready for review June 19, 2024 10:54
socketioxide/src/packet.rs Fixed Show fixed Hide fixed
socketioxide/src/operators.rs Fixed Show fixed Hide fixed
socketioxide/src/operators.rs Fixed Show fixed Hide fixed
socketioxide/src/ns.rs Fixed Show fixed Hide fixed
socketioxide/src/io.rs Fixed Show fixed Hide fixed
socketioxide/src/operators.rs Fixed Show fixed Hide fixed
socketioxide/src/client.rs Fixed Show fixed Hide fixed
socketioxide/src/ns.rs Fixed Show fixed Hide fixed
socketioxide/src/io.rs Fixed Show fixed Hide fixed
@Totodore Totodore force-pushed the feat-namespace-routing branch 3 times, most recently from b5bd1d7 to 302e2a2 Compare June 24, 2024 13:12
socketioxide/src/operators.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/socket.rs Fixed Show fixed Hide fixed
@Totodore Totodore force-pushed the feat-namespace-routing branch 2 times, most recently from 6c1c61c to a5c260d Compare June 24, 2024 13:25
socketioxide/src/io.rs Fixed Show fixed Hide fixed
@Totodore
Copy link
Owner Author

After multiple experimentations and attempts to solve this problem I decided to report the following features for future PRs:

  • The extraction of parameters. Only the namespace path will be extracted.
  • The usage of dynamic namespace with broadcast operators. Meaning that it won't be possible to select a dynamic namespace with the io.of(...) operator.

@Totodore Totodore merged commit 4ab5215 into main Jun 25, 2024
13 checks passed
@Totodore Totodore deleted the feat-namespace-routing branch June 29, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic Namespaces
1 participant