Skip to content

Commit 4327f94

Browse files
committed
Use doubles to calculate number of producer threads
Not BigDecimal, which fails when rounding is not possible. References #287
1 parent c9f505e commit 4327f94

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/main/java/com/rabbitmq/perf/MulticastSet.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.rabbitmq.client.impl.recovery.AutorecoveringConnection;
3030
import com.rabbitmq.perf.PerfTest.EXIT_WHEN;
3131
import java.io.IOException;
32-
import java.math.BigDecimal;
3332
import java.net.URISyntaxException;
3433
import java.security.KeyManagementException;
3534
import java.security.NoSuchAlgorithmException;
@@ -148,10 +147,8 @@ protected static int nbThreadsForProducerScheduledExecutorService(MulticastParam
148147
: params.getPublishingInterval();
149148
long publishingIntervalMs = publishingInterval.toMillis();
150149

151-
BigDecimal publishingIntervalSeconds = new BigDecimal(publishingIntervalMs)
152-
.divide(new BigDecimal(1000));
153-
BigDecimal rate = new BigDecimal(producerThreadCount)
154-
.divide(publishingIntervalSeconds);
150+
double publishingIntervalSeconds = (double) publishingIntervalMs / 1000d;
151+
double rate = (double) producerThreadCount / publishingIntervalSeconds;
155152
/**
156153
* Why 100? This is arbitrary. We assume 1 thread is more than enough to handle
157154
* the publishing of 100 messages in 1 second, the fastest rate
@@ -162,10 +159,10 @@ protected static int nbThreadsForProducerScheduledExecutorService(MulticastParam
162159
* which seems reasonable.
163160
* There's a command line argument to override this anyway.
164161
*/
165-
int threadCount = rate.intValue() / 100 + 1;
162+
int threadCount = (int) (rate / 100d) + 1;
166163
LOGGER.debug("Using {} thread(s) to schedule {} publisher(s) publishing every {} ms",
167164
threadCount, producerThreadCount, publishingInterval.toMillis()
168-
);
165+
);
169166
return threadCount;
170167
} else {
171168
return producerExecutorServiceNbThreads;

src/test/java/com/rabbitmq/perf/MulticastSetTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void nbThreadsForProducerScheduledExecutorServiceOneThreadEvery100Produce
128128
"300,1000,4",
129129
"200,100,21",
130130
"2000,1000,21",
131+
"1000,60000,1"
131132
})
132133
void nbThreadsForProducerScheduledExecutorServiceOK(int producerCount, int publishingIntervalMs,
133134
int expectedThreadCount) {

0 commit comments

Comments
 (0)