Fixed possible spin loop in chat room selection when sending batches.
@@ -600,12 +600,13 @@ public class CometDLoadClient implements MeasureConverter {
private long sendBatches(int batchSize, long batchPause, String chat, String channel, LoadBayeuxClient client) {
long expected = 0;
+ List<Integer> rooms = new ArrayList<>(roomMap.keySet());
client.startBatch();
for (int b = 0; b < batchSize; ++b) {
int room = -1;
AtomicInteger clientsPerRoom = null;
while (clientsPerRoom == null || clientsPerRoom.get() == 0) {
- room = nextRandom(roomMap.size());
+ room = rooms.get(nextRandom(rooms.size()));
clientsPerRoom = roomMap.get(room);
}
Map<String, Object> message = new HashMap<>(5);
@@ -617,7 +618,7 @@ public class CometDLoadClient implements MeasureConverter {
message.put(START_FIELD, System.nanoTime());
String startDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(System.currentTimeMillis());
message.put(START_DATE_FIELD, startDate);
- message.put(Config.ID_FIELD, String.valueOf(ids.incrementAndGet()) + channel);
+ message.put(Config.ID_FIELD, ids.incrementAndGet() + channel);
ClientSessionChannel clientChannel = client.getChannel(getChannelId(channel + "/" + room));
clientChannel.publish(message);
clientChannel.release();
@@ -680,7 +681,7 @@ public class CometDLoadClient implements MeasureConverter {
totLatency.addAndGet(latency);
}
- private boolean waitForMessages(long expected) throws InterruptedException {
+ private void waitForMessages(long expected) throws InterruptedException {
long arrived = messages.get();
long lastArrived = 0;
int maxRetries = 20;
@@ -701,10 +702,8 @@ public class CometDLoadClient implements MeasureConverter {
}
if (arrived < expected) {
System.err.printf("Interrupting wait for messages %d/%d%n", arrived, expected);
- return false;
} else {
System.err.printf("All messages arrived %d/%d%n", arrived, expected);
- return true;
}
}
