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

API to support start/stop accepting connections #1741

Merged
merged 3 commits into from
Aug 26, 2021

Conversation

tkountis
Copy link
Contributor

Motivation:

Expose a way a user can yield accepting connection on server side, and resume on demand.?

Modifications:

ServerContext now supports an additional acceptConnections(bool) API that can be used to
hint to the server the need for start/stop accepting.

Result:

More ways to control the service on-demand.

@tkountis tkountis force-pushed the capacity/stop-accepting branch from d2ac0b3 to cb20348 Compare August 18, 2021 00:45
@tkountis tkountis force-pushed the capacity/stop-accepting branch from cb20348 to e07e22c Compare August 18, 2021 09:29
Copy link
Contributor

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments and a suggestion for tests readability, but in general LGTM.

@tkountis tkountis force-pushed the capacity/stop-accepting branch 2 times, most recently from 8235edf to e558089 Compare August 18, 2021 14:57
@tkountis tkountis force-pushed the capacity/stop-accepting branch from e558089 to 620f978 Compare August 18, 2021 15:05
* tcp_max_syn_backlog</a>). These additional parameters may affect the behavior of new flows when the service
* is not accepting.
* <p>
* Depending on how long this stays in the {@code false} state, it may affect other timeouts (i.e., connect-timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like this may make the behaviour worse for clients since they might wait until connect timeout to learn that the server is not accepting connections. Is it possible to adjust the backlog queues to zero while not accepting connections and reject the queued connections as if the queue had been full?

Not being able to fully reject the inbound connection seems bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation. That indeed may be a problem, and this is the reason I am trying to document all expectations in the javadoc so users can make an educated decision. I want to avoid making a global decision here, and give the tools to the user's to tune accordingly.

Copy link
Contributor

@chemicL chemicL Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. I was wondering whether it makes more sense to not expose such capability if we can't provide an extensive guideline how to configure the TCP settings. Wouldn't a mechanism for accepting the connection and immediately replying with a 503 HTTP error code (immediately closing the connection after the write buffer has been flushed) be more "by the book"? For gRPC that's also safe as the clients should honor that code according to this table: https://grpc.github.io/grpc/core/md_doc_http-grpc-status-mapping.html

Copy link
Member

@idelpivnitskiy idelpivnitskiy Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main problems of accepting a connections:

  1. TLS handshake overhead. It might produce significant CPU usage, affecting other requests.
  2. There is no guarantee that a new attempt to connect supports/expects HTTP protocol or will send a request we can respond to.

Therefore, this mechanism is introduced to stop as soon as possible.

@tkountis tkountis force-pushed the capacity/stop-accepting branch from 620f978 to 673526a Compare August 19, 2021 13:46
Motivation:

Expose a way a user can yield accepting connection on server side, and resume on demand.?

Modifications:

ServerContext now supports an additional `acceptConnections(bool)` API that can be used to
hint to the server the need for start/stop accepting.

Result:

More ways to control the service on-demand.
@tkountis tkountis force-pushed the capacity/stop-accepting branch from 673526a to 95921f8 Compare August 19, 2021 13:49
@tkountis tkountis self-assigned this Aug 19, 2021
@tkountis
Copy link
Contributor Author

Build failure due: #1579

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the patch is applied

* SYN backlog (i.e., in case of Linux <a href="https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt">
* tcp_max_syn_backlog</a>). These additional parameters may affect the behavior of new flows when the service
* is not accepting.
* SYN backlog (in the case of linux). This can be tuned:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider clarifying that it can be tuned at OS level or per server instance using ServiceTalkSocketOptions#SO_BACKLOG option.

I know that you don't have access to HTTP classes from here, but maybe even without referencing an exact method, consider clarifying that they need to use listenSocketOption on the builder, not a socketOption method. It might be a useful hint.

Copy link
Contributor Author

@tkountis tkountis Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not tunable on the per server instance. so_backlog = accept_queue. SYN backlog is a different setting, only at the OS level. I am not elaborating further on it, because its very OS specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying!

@tkountis
Copy link
Contributor Author

Another failure due to #1579

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@tkountis tkountis merged commit 6beebe8 into apple:main Aug 26, 2021
@tkountis tkountis deleted the capacity/stop-accepting branch August 26, 2021 19:13
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

Successfully merging this pull request may close these issues.

4 participants