Conversation
fda7651 to
27fcbf8
Compare
There was a problem hiding this comment.
Thread.currentThread().interrupt(); maybe and/or rethrow
There was a problem hiding this comment.
Thanks. Addressed it.
27fcbf8 to
e9d329a
Compare
| public void stop() | ||
| { | ||
| if (activeConnections.get() != 0) { | ||
| long graceFullShutDownTime = (int) server.getAttribute(GRACEFUL_SHUTDOWN_TIME); |
| } | ||
| catch (InterruptedException e) { | ||
| log.error("Sleep has been interrupted, while waiting for active requests to be zero"); | ||
| Thread.currentThread().interrupt(); |
There was a problem hiding this comment.
Should this further wait if the current thread is interrupted early?
|
@jihoonson Incorporated your comments |
| { | ||
| if (activeConnections.get() != 0) { | ||
| long graceFullShutDownTime = (int) server.getAttribute(GRACEFUL_SHUTDOWN_TIME); | ||
| long graceFulShutDownTime = (long) server.getAttribute(GRACEFUL_SHUTDOWN_TIME); |
There was a problem hiding this comment.
graceFul should be graceful.
| @Override | ||
| public void stop() | ||
| { | ||
| if (activeConnections.get() != 0) { |
There was a problem hiding this comment.
I think activeConnections.get() > 0 is more appropriate because we don't have to wait even if it returns a negative value due to some bugs.
| } | ||
| catch (InterruptedException e) { | ||
| log.error("Sleep has been interrupted, while waiting for active requests to be zero"); | ||
| stopImmediately(); |
There was a problem hiding this comment.
As you added to docs, graceful shutdown is useful to wait for running queries to be completed. So, I think when an InterruptedException occurs earlier while waiting for the given GRACEFUL_SHUTDOWN_TIME, we first check activeConnections is 0 and then further wait for remaining time if there remains more active connections.
What do you think?
There was a problem hiding this comment.
When an InterruptedException occurs, the thread should finish whatever it was doing as soon as possible. In this specific case , it should shutdown ASAP
| private static final Logger log = new Logger(JettyServerModule.class); | ||
|
|
||
| private static final AtomicInteger activeConnections = new AtomicInteger(); | ||
| private static final String GRACEFUL_SHUTDOWN_TIME = "graceful_shutdown_time"; |
There was a problem hiding this comment.
minor: gracefulShutdownTimeout would be more consistent with the property name.
| log.info("Waiting for [%s] milliseconds for active requests to be zero, current active requests=[%s]", | ||
| gracefulShutDownTime, activeConnections.get()); | ||
| try { | ||
| Thread.sleep(gracefulShutDownTime); |
There was a problem hiding this comment.
A couple questions.
- Will the server always unannounce itself before entering this
stop()code? How is that assured? If it happens, that's good; but if not, that would mean new requests could keep coming in continuously even while waiting for shutdown. Inevitably the last few will fail. - Could this code check
activeConnectionsevery few ms, rather than always sleeping for the gracefulShutdownTimeout? Otherwise, it looks like an extra 5s of potentially needless delay. - If both of the above are assured, then I think it could make sense to set the default gracefulShutdownTimeout to somewhat longer, like a few minutes.
| public void stop() | ||
| { | ||
| if (activeConnections.get() > 0) { | ||
| long gracefulShutDownTime = (long) server.getAttribute(GRACEFUL_SHUTDOWN_TIME); |
There was a problem hiding this comment.
minor: gracefulShutdownTimeout would be more consistent with the property name.
57826ae to
127ed33
Compare
|
|
|
||
| @JsonProperty | ||
| @NotNull | ||
| private Period gracefulShutdownTimeout = new Period("PT15s"); |
There was a problem hiding this comment.
documentation says it is 5s by default. should probably be PT5s .
| long startTime = System.currentTimeMillis(); | ||
| long gracefulShutDownTimeout = (long) server.getAttribute(GRACEFUL_SHUTDOWN_TIMEOUT); | ||
|
|
||
| while (activeConnections.get() > 0 && |
There was a problem hiding this comment.
I think activeConnections is number of socket connections setup and not necessarily number of requests in progress or queued. connection pooling clients would generally never close connections and the count here might not reduce.
is there a more reliable way of looking at number of requests being processed instead ?
374937d to
e6181c4
Compare
e6181c4 to
0d07ba5
Compare
|
Done in #5429 |
We see queries failing while realtime handoff is happening mainly because Jetty is not being shutdown gracefully. Here is the error
Failure getting results from[http://host:port/druid/v2/] because of [org.jboss.netty.channel.ChannelException: Channel disconnected
The solution is to add a graceful shutdown. This will also reduce failed queries on shutdown on the broker and historical also.