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

Revert erlang:port_command/2 to gen_tcp:send/2 change #7921

Merged
merged 1 commit into from
Apr 18, 2023

Conversation

ansd
Copy link
Member

@ansd ansd commented Apr 18, 2023

Revert the change introduced in #7900

RabbitMQ 3.12 will require OTP 25 (not yet OTP 26).

The use of macro OTP_RELEASE was wrong because RabbitMQ can be compiled with OTP 25, but run with OTP 26. Macros are evaluated at compile time.

An alternative runtime equivalent would have been

1> erlang:system_info(otp_release).
"26"

Revert the change introduced in #7900

RabbitMQ 3.12 will require OTP 25 (not yet OTP 26).

The use of macro `OTP_RELEASE` was wrong because RabbitMQ can be
compiled with OTP 25, but run with OTP 26. Macros are evaluated at
compile time.

An alternative runtime equivalent would have been
```
1> erlang:system_info(otp_release).
"26"
```
@michaelklishin michaelklishin merged commit d561c78 into main Apr 18, 2023
@michaelklishin michaelklishin deleted the revert-port-command branch April 18, 2023 11:02
ansd added a commit that referenced this pull request Apr 18, 2023
Revert erlang:port_command/2 to gen_tcp:send/2 change (backport #7921)
@michaelklishin
Copy link
Member

Since we seemingly cannot reproduce the original issue (a slow scan of process mailbox in gen_tcp:send/2), this will likely get re-reverted eventually.

ansd added a commit that referenced this pull request Apr 18, 2023
Follow up of #7913
and #7921

This commit uses the approach explained in erlang/otp#7130 (comment)

We cannot use the macro `?OTP_RELEASE` since macros are evaluated at
compile time. RabbitMQ can be compiled with OTP 25 and executed with OTP
26. Therefore, we use `erlang:system_info(otp_release)` instead.
As `erlang:system_info/1` might be costly, we store the send function in
persistent_term.

For OTP 25, we use the "old tcp send workaround" (i.e.
`erlang:port_command/2`) which avoids expensive selective receives.
For OTP 26, we use `gen_tcp:send/2` which uses the optimised selective
receive.

Once the minimum required version becomes OTP 26, we can just switch to
`gen_tcp:send/2` and delete the `inet_reply` handling code in the various
RabbitMQ reader and writer processes.

Note that `rabbit_net:port_command/2` is not only used by RabbitMQ server,
but also by the AMQP 0.9.1 client.
Therefore, instead of putting the OTP version (or send function) into
persistent_term within the rabbit app, we just do it the first time
`rabbit_net:port_command/2` is invoked.
(`rabbit_common` is just a library without supervision hierarchy.)
mergify bot pushed a commit that referenced this pull request Apr 24, 2023
Follow up of #7913
and #7921

This commit uses the approach explained in erlang/otp#7130 (comment)

We cannot use the macro `?OTP_RELEASE` since macros are evaluated at
compile time. RabbitMQ can be compiled with OTP 25 and executed with OTP
26. Therefore, we use `erlang:system_info(otp_release)` instead.
As `erlang:system_info/1` might be costly, we store the send function in
persistent_term.

For OTP 25, we use the "old tcp send workaround" (i.e.
`erlang:port_command/2`) which avoids expensive selective receives.
For OTP 26, we use `gen_tcp:send/2` which uses the optimised selective
receive.

Once the minimum required version becomes OTP 26, we can just switch to
`gen_tcp:send/2` and delete the `inet_reply` handling code in the various
RabbitMQ reader and writer processes.

Note that `rabbit_net:port_command/2` is not only used by RabbitMQ server,
but also by the AMQP 0.9.1 client.
Therefore, instead of putting the OTP version (or send function) into
persistent_term within the rabbit app, we just do it the first time
`rabbit_net:port_command/2` is invoked.
(`rabbit_common` is just a library without supervision hierarchy.)

(cherry picked from commit 6b4d881)
michaelklishin added a commit that referenced this pull request Apr 24, 2023
if the input is given as a map.

References #7931, #7921
michaelklishin added a commit that referenced this pull request Apr 24, 2023
if the input is given as a map.

References #7931, #7921
mergify bot pushed a commit that referenced this pull request Apr 24, 2023
if the input is given as a map.

References #7931, #7921

(cherry picked from commit ddf7926)
michaelklishin pushed a commit that referenced this pull request May 28, 2023
Follow up of #7913
and #7921

This commit uses the approach explained in erlang/otp#7130 (comment)

We cannot use the macro `?OTP_RELEASE` since macros are evaluated at
compile time. RabbitMQ can be compiled with OTP 25 and executed with OTP
26. Therefore, we use `erlang:system_info(otp_release)` instead.
As `erlang:system_info/1` might be costly, we store the send function in
persistent_term.

For OTP 25, we use the "old tcp send workaround" (i.e.
`erlang:port_command/2`) which avoids expensive selective receives.
For OTP 26, we use `gen_tcp:send/2` which uses the optimised selective
receive.

Once the minimum required version becomes OTP 26, we can just switch to
`gen_tcp:send/2` and delete the `inet_reply` handling code in the various
RabbitMQ reader and writer processes.

Note that `rabbit_net:port_command/2` is not only used by RabbitMQ server,
but also by the AMQP 0.9.1 client.
Therefore, instead of putting the OTP version (or send function) into
persistent_term within the rabbit app, we just do it the first time
`rabbit_net:port_command/2` is invoked.
(`rabbit_common` is just a library without supervision hierarchy.)

(cherry picked from commit 6b4d881)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants