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

Retrieving number of connected sockets using fetchSockets without getting all socket information #515

Open
MatanYemini opened this issue Oct 11, 2023 · 5 comments

Comments

@MatanYemini
Copy link

Hi,

We will need to add a function with the functionality mentioned in the title

(Retrieving number of connected sockets using fetchSockets without getting all socket information)

Currently, in high loaded systems, we have too much traffic in redis since each handshake of a socket contains a lot of information (all the headers, the session info, etc)

Thanks.

I will try to push a PR soon.

@darrachequesne
Copy link
Member

Hi! Yes, as you have noted the fetchSockets() method transfers a lot of data.

You should use the serverSideEmit() method instead:

io.serverSideEmit("hello", "world");

// And on the receiving side:
io.on("hello", (arg1) => {
  console.log(arg1); // prints "world"
});

Reference: https://socket.io/docs/v4/server-instance/#serversideemit

@MatanYemini
Copy link
Author

Yeah. I have used that for now.

@darrachequesne What do you think about adding the "count" as a separate function? You don't think it would be usable?

I have also an example of a patch with a new function.

@darrachequesne
Copy link
Member

What do you think about adding the "count" as a separate function?

I'm not sure that's a good idea, because in most cases I think one wants to count the number of users, not the number of sockets (since a single user can have multiple connections). What do you think?

@cody-evaluate
Copy link

I second this. I do not care if socket count is not always 1 to 1 with user count. I need a way to count sockets without pulling all data over the wire.

@MatanYemini
Copy link
Author

@darrachequesne - Sometimes I actually more interested in the sockets as opposed to the users as @cody-evaluate mentioned.

An example (my case) for that is for horizontal scaling purposes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants