Skip to content

Commit 65205ea

Browse files
author
David R. MacIver
committed
make sure we flush the output stream at least once a second to deal with cases where messages are arriving quickly enough to not timeout but slowly enough to take a while to fill up the buffer
1 parent 0366de7 commit 65205ea

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/com/rabbitmq/tools/Tracer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class Tracer implements Runnable {
7171

7272
final static int LOG_QUEUE_SIZE = 1024 * 1024;
7373
final static int BUFFER_SIZE = 10 * 1024 * 1024;
74+
final static int MAX_TIME_BETWEEN_FLUSHES = 1000;
7475

7576
private static class AsyncLogger extends Thread{
7677
final PrintStream ps;
@@ -90,9 +91,19 @@ void printMessage(Object message){
9091
}
9192
}
9293

94+
long lastFlush = System.currentTimeMillis();
95+
void maybeFlush(){
96+
long now = System.currentTimeMillis();
97+
if(now - lastFlush > MAX_TIME_BETWEEN_FLUSHES){
98+
ps.flush();
99+
lastFlush = now;
100+
}
101+
}
102+
93103
@Override public void run(){
94104
try {
95105
while(true){
106+
maybeFlush();
96107
Object message = queue.poll(50, TimeUnit.MILLISECONDS);
97108
if(message != null) printMessage(message);
98109
else ps.flush();

0 commit comments

Comments
 (0)