ifesdjeen commented on code in PR #3274:
URL: https://github.com/apache/cassandra/pull/3274#discussion_r1598437330
##########
src/java/org/apache/cassandra/transport/Dispatcher.java:
##########
@@ -154,14 +323,49 @@ public String description()
{
return request.toString();
}
+
+ @Override
+ public String toString()
+ {
+ return "RequestProcessor{" +
+ "request=" + request +
+ ", approxStartTimeNanos=" + startTimeNanos +
+ '}';
+ }
+ }
+
+ /**
+ * Checks if the item in the head of the queue has spent more than allowed
time in the queue.
+ */
+ @Override
+ public boolean hasQueueCapacity()
+ {
+ double threshold =
DatabaseDescriptor.getNativeTransportQueueMaxItemAgeThreshold();
+ if (threshold <= 0)
+ return true;
+
+ return requestExecutor.oldestTaskQueueTime() <
(DatabaseDescriptor.getNativeTransportTimeout(TimeUnit.NANOSECONDS) *
threshold);
}
/**
* Note: this method may be executed on the netty event loop, during
initial protocol negotiation; the caller is
* responsible for cleaning up any global or thread-local state. (ex.
tracing, client warnings, etc.).
*/
- private static Message.Response processRequest(ServerConnection
connection, Message.Request request, Overload backpressure, long startTimeNanos)
+ private static Message.Response processRequest(ServerConnection
connection, Message.Request request, Overload backpressure, RequestTime
requestTime)
{
+ long queueTime = requestTime.timeSpentInQueueNanos();
+
+ // If we have already crossed the max timeout for all possible RPCs,
we time out the query immediately.
+ // We do not differentiate between query types here, since if we got
into a situation when, say, we have a PREPARE
+ // query that is stuck behind the EXECUTE query, we would rather time
it out and catch up with a backlog, expecting
+ // that the bursts are going to be short-lived.
+ ClientMetrics.instance.queueTime(queueTime, TimeUnit.NANOSECONDS);
+ if (queueTime >
DatabaseDescriptor.getNativeTransportTimeout(TimeUnit.NANOSECONDS))
Review Comment:
Did this:
```
private static long native_transport_timeout_nanos_cached = -1;
public static long getNativeTransportTimeout(TimeUnit timeUnit)
{
if (timeUnit == TimeUnit.NANOSECONDS)
{
if (native_transport_timeout_nanos_cached == -1)
native_transport_timeout_nanos_cached =
conf.native_transport_timeout.to(TimeUnit.NANOSECONDS);
return native_transport_timeout_nanos_cached;
}
return conf.native_transport_timeout.to(timeUnit);
}
```
But arguably we should have a more generic pattern for these things. Maybe
even always precompute millis nanos and micros. Should be extremely cheap, and
constant time, if we use a tiny array.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]