use of org.apache.activemq.artemis.utils.TokenBucketLimiterImpl in project activemq-artemis by apache.
the class SoakSender method run.
public void run() throws Exception {
connect();
boolean runInfinitely = perfParams.getDurationInMinutes() == -1;
BytesMessage message = session.createBytesMessage();
byte[] payload = SoakBase.randomByteArray(perfParams.getMessageSize());
message.writeBytes(payload);
final int modulo = 10000;
TokenBucketLimiter tbl = perfParams.getThrottleRate() != -1 ? new TokenBucketLimiterImpl(perfParams.getThrottleRate(), false) : null;
boolean transacted = perfParams.isSessionTransacted();
int txBatchSize = perfParams.getBatchSize();
boolean display = true;
long start = System.currentTimeMillis();
long moduleStart = start;
AtomicLong count = new AtomicLong(0);
while (true) {
try {
producer.send(message);
count.incrementAndGet();
if (transacted) {
if (count.longValue() % txBatchSize == 0) {
session.commit();
}
}
long totalDuration = System.currentTimeMillis() - start;
if (display && count.longValue() % modulo == 0) {
double duration = (1.0 * System.currentTimeMillis() - moduleStart) / 1000;
moduleStart = System.currentTimeMillis();
SoakSender.log.info(String.format("sent %s messages in %2.2fs (time: %.0fs)", modulo, duration, totalDuration / 1000.0));
}
if (tbl != null) {
tbl.limit();
}
if (!runInfinitely && totalDuration > perfParams.getDurationInMinutes() * SoakBase.TO_MILLIS) {
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
SoakSender.log.info(String.format("Sent %s messages in %s minutes", count, perfParams.getDurationInMinutes()));
SoakSender.log.info("END OF RUN");
if (connection != null) {
connection.close();
connection = null;
}
}
Aggregations