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

Don't use blocking recv #2

Open
zuiderkwast opened this issue Jun 9, 2022 · 5 comments
Open

Don't use blocking recv #2

zuiderkwast opened this issue Jun 9, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@zuiderkwast
Copy link
Collaborator

When gen_tcp:recv (or ssl:recv) is used, the process can't respond to supervisor events. We should use {active, once} or {active, N} instead.

We use one process to send data to a socket and another to receive the responses. Currently the sending process is the controlling process. We should make the receive process the controlling process instead, because gen_tcp:send can block.

@drmull
Copy link
Collaborator

drmull commented Jun 10, 2022

Need to see if this has any performance impact when reading big bulk strings and similar. I am not sure if the reading process really needs to be part of the supervision tree or if it is ok to just put the gen_servers under supervision

@zuiderkwast
Copy link
Collaborator Author

Yes, we should try this in an isolated test: A minimal example program just sending data to a server that's streaming it back. Three versions would be nice:

  1. One process to send and passive receive from gen_tcp
  2. Two processes, active recv
  3. Two processes, passive recv

Supervision is not a must for any process, but it makes the design more robust. If it turns out version 2 is faster, I think we can live with spawn_link for the receiving process.

Btw, how likely is it than gen_tcp:send will block in our pipeline scenarios? It happens when the send buffer is full. Redis may be busy or the network is slow. If it's likely, it's another reason for using passive mode and the receiving process be controlling process.

@drmull
Copy link
Collaborator

drmull commented Jun 11, 2022

Btw, how likely is it than gen_tcp:send will block in our pipeline scenarios?

The note on gen_tcp:send gives the impression that it will not block, at least not in the send buffer full scenario.

https://www.erlang.org/doc/man/gen_tcp.html#send-2

@zuiderkwast
Copy link
Collaborator Author

True, in only blocks if the socket backend is used. Maybe we want to support that in the future though.

@zuiderkwast zuiderkwast reopened this Jun 12, 2022
@ghost
Copy link

ghost commented Jul 26, 2022

The note on gen_tcp:send gives the impression that it will not block, at least not in the send buffer full scenario.

but

the function can hang even when using 'inet' backend if the internal buffers are full

@zuiderkwast zuiderkwast added the enhancement New feature or request label Nov 13, 2023
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

No branches or pull requests

2 participants