Elffuss BraidHub

kikocis/java-driver public

Backport Connection.Flusher improvements (JAVA-814).
Changeset09d548c3199c83196d5acf98c3c945474c4e7934096719eacca658b763307493
Authorolim7t <omichallat+github@gmail.com> · 2015-08-04 19:15 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-08-04 19:32 +02:00
Parentsc89149fa6140

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +5 −16
@@ -19,14 +19,12 @@
1919 import java.net.InetSocketAddress;
2020 import java.util.HashSet;
2121 import java.util.Iterator;
22-import java.util.List;
2322 import java.util.Queue;
2423 import java.util.concurrent.*;
2524 import java.util.concurrent.atomic.AtomicBoolean;
2625 import java.util.concurrent.atomic.AtomicInteger;
2726 import java.util.concurrent.atomic.AtomicReference;
2827
29-import com.google.common.collect.Lists;
3028 import com.google.common.collect.MapMaker;
3129 import com.google.common.util.concurrent.*;
3230 import io.netty.bootstrap.Bootstrap;
@@ -827,8 +825,6 @@
827825 final Queue<FlushItem> queued = new ConcurrentLinkedQueue<FlushItem>();
828826 final AtomicBoolean running = new AtomicBoolean(false);
829827 final HashSet<Channel> channels = new HashSet<Channel>();
830- final List<FlushItem> flushed = Lists.newArrayListWithExpectedSize(50);
831- int runsSinceFlush = 0;
832828 int runsWithNoWork = 0;
833829
834830 private Flusher(EventLoop eventLoop) {
@@ -851,20 +847,13 @@
851847 while (null != (flush = queued.poll())) {
852848 channels.add(flush.channel);
853849 flush.channel.write(flush.request).addListener(flush.listener);
854- flushed.add(flush);
855850 doneWork = true;
856851 }
857852
858- runsSinceFlush++;
859-
860- if (!doneWork || runsSinceFlush > 2 || flushed.size() > 50) {
861- for (Channel channel : channels)
862- channel.flush();
863-
864- channels.clear();
865- flushed.clear();
866- runsSinceFlush = 0;
867- }
853+ // Always flush what we have (don't artificially delay to try to coalesce more messages)
854+ for (Channel channel : channels)
855+ channel.flush();
856+ channels.clear();
868857
869858 if (doneWork) {
870859 runsWithNoWork = 0;
@@ -878,7 +867,7 @@
878867 }
879868
880869 EventLoop eventLoop = eventLoopRef.get();
881- if(eventLoop != null) {
870+ if (eventLoop != null) {
882871 eventLoop.schedule(this, 10000, TimeUnit.NANOSECONDS);
883872 }
884873 }