Skip to content

Commit

Permalink
Add per host queues.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkozlowski committed Jul 16, 2021
1 parent 1972ca2 commit 0f2942a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,26 @@ public DialogueChannel build() {

ImmutableList<Channel> perHostChannels = IntStream.range(0, channels.size())
.mapToObj(index -> new ChannelAndFactory() {

private final LimitedChannel stickyLimitedChannel =
StickyConcurrencyLimitedChannel.createForQueueKey(
nodeSelectionChannel, cf.channelName());
private final Channel queueOverride =
QueuedChannel.createPerHost(cf, stickyLimitedChannel, index);

@Override
public EndpointChannel endpoint(Endpoint endpoint) {
EndpointChannel endpointChannel = channelFactory.endpoint(endpoint);
return request -> {
request.attachments().put(QueueAttachments.QUEUE_OVERRIDE, queueOverride);
nodeSelectionChannel.routeToHost(index, request);
return endpointChannel.execute(request);
};
}

@Override
public ListenableFuture<Response> execute(Endpoint endpoint, Request request) {
nodeSelectionChannel.routeToHost(index, request);
return channelFactory.endpoint(endpoint).execute(request);
return endpoint(endpoint).execute(request);
}
})
.collect(ImmutableList.toImmutableList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ static QueuedChannel createPerHost(Config cf, LimitedChannel delegate, int hostI
return new QueuedChannel(
delegate,
cf.channelName(),
stickyInstrumentation(
DialogueClientMetrics.of(cf.clientConf().taggedMetricRegistry()), cf.channelName()),
perHostInstrumentation(
DialogueClientMetrics.of(cf.clientConf().taggedMetricRegistry()), cf.channelName(), hostIndex),
cf.maxQueueSize());
}

Expand Down Expand Up @@ -401,15 +401,22 @@ public Timer requestQueuedTime() {

static QueuedChannelInstrumentation perHostInstrumentation(
DialogueClientMetrics metrics, String channelName, int hostIndex) {
String hostIndexString = Integer.toString(hostIndex);
return new QueuedChannelInstrumentation() {
@Override
public Counter requestsQueued() {
return metrics.requestsPerhostQueued().channelName(channelName).hostIndex(hostIndex);
return metrics.requestsPerhostQueued()
.channelName(channelName)
.hostIndex(hostIndexString)
.build();
}

@Override
public Timer requestQueuedTime() {
return metrics.requestStickyQueuedTime(channelName);
return metrics.requestPerhostQueuedTime()
.channelName(channelName)
.hostIndex(hostIndexString)
.build();
}
};
}
Expand Down

0 comments on commit 0f2942a

Please sign in to comment.