Skip to content

Commit e7798c8

Browse files
committed
Speed up ChannelPool offering
1 parent 3d5a253 commit e7798c8

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,28 @@ public boolean offer(Channel channel, Object partitionKey) {
243243
if (isTtlExpired(channel, now))
244244
return false;
245245

246-
boolean added = partitions.computeIfAbsent(partitionKey, pk -> new ConcurrentLinkedQueue<>()).add(new IdleChannel(channel, now));
247-
if (added)
248-
channelId2Creation.putIfAbsent(channelId(channel), new ChannelCreation(now, partitionKey));
246+
boolean offered = offer0(channel, partitionKey,now);
247+
if (offered) {
248+
registerChannelCreation(channel, partitionKey, now);
249+
}
249250

250-
return added;
251+
return offered;
251252
}
252-
253+
254+
private boolean offer0(Channel channel, Object partitionKey, long now) {
255+
ConcurrentLinkedQueue<IdleChannel> partition = partitions.get(partitionKey);
256+
if (partition == null) {
257+
partition = partitions.computeIfAbsent(partitionKey, pk -> new ConcurrentLinkedQueue<>());
258+
}
259+
return partition.add(new IdleChannel(channel, now));
260+
}
261+
262+
private void registerChannelCreation(Channel channel, Object partitionKey, long now) {
263+
if (channelId2Creation.containsKey(partitionKey)) {
264+
channelId2Creation.putIfAbsent(channelId(channel), new ChannelCreation(now, partitionKey));
265+
}
266+
}
267+
253268
/**
254269
* {@inheritDoc}
255270
*/

0 commit comments

Comments
 (0)