-
Notifications
You must be signed in to change notification settings - Fork 184
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
Conversation
d2ac0b3
to
cb20348
Compare
cb20348
to
e07e22c
Compare
There was a problem hiding this 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.
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Outdated
Show resolved
Hide resolved
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerContext.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerContext.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerContext.java
Outdated
Show resolved
Hide resolved
8235edf
to
e558089
Compare
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Show resolved
Hide resolved
e558089
to
620f978
Compare
...talk-http-netty/src/main/java/io/servicetalk/http/netty/H2ServerParentConnectionContext.java
Outdated
Show resolved
Hide resolved
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Outdated
Show resolved
Hide resolved
* 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- TLS handshake overhead. It might produce significant CPU usage, affecting other requests.
- 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.
620f978
to
673526a
Compare
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.
673526a
to
95921f8
Compare
Build failure due: #1579 |
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerListenContext.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerListenContext.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerListenContext.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerListenContext.java
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerListenContext.java
Show resolved
Hide resolved
...etalk-transport-api/src/main/java/io/servicetalk/transport/api/ServiceTalkSocketOptions.java
Show resolved
Hide resolved
...talk-http-netty/src/main/java/io/servicetalk/http/netty/H2ServerParentConnectionContext.java
Outdated
Show resolved
Hide resolved
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Outdated
Show resolved
Hide resolved
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Outdated
Show resolved
Hide resolved
...tp-netty/src/test/java/io/servicetalk/http/netty/ConnectionAcceptingNettyHttpServerTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying!
...talk-tcp-netty-internal/src/main/java/io/servicetalk/tcp/netty/internal/TcpServerBinder.java
Outdated
Show resolved
Hide resolved
servicetalk-transport-api/src/main/java/io/servicetalk/transport/api/ServerListenContext.java
Show resolved
Hide resolved
Another failure due to #1579 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
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 tohint to the server the need for start/stop accepting.
Result:
More ways to control the service on-demand.