upthewaterspout commented on a change in pull request #25: GEODE-6148: improve
performance of Prepopulate
URL: https://github.com/apache/geode-benchmarks/pull/25#discussion_r240838275
##########
File path:
geode-benchmarks/src/main/java/org/apache/geode/benchmark/tasks/PrePopulateRegion.java
##########
@@ -50,14 +56,36 @@ public PrePopulateRegion(long keyRangeToPrepopulate) {
public void run(TestContext context) {
Cache serverCache = (Cache) context.getAttribute("SERVER_CACHE");
Region region = serverCache.getRegion("region");
+
+ int numLocators = context.getHostsForRole(LOCATOR).size();
+ int numServers = context.getHostsForRole(SERVER).size();
+ int serverIndex = context.getJvmID() - numLocators;
+ int numPutsPerServer = (int) this.keyRangeToPrepopulate / numServers;
+
+ AtomicInteger lowBound = new AtomicInteger();
+ AtomicInteger highBound = new AtomicInteger();
+
+ // calculate non-overlapping key ranges for each server
+ lowBound.set(numPutsPerServer * serverIndex);
+ highBound.set(numPutsPerServer * (serverIndex + 1));
+ if (serverIndex == (numServers - 1)) {
+ highBound.getAndAdd((int) this.keyRangeToPrepopulate % (serverIndex +
1));
+ }
+
+ // build a map of to put to the server
+ Map<Long, PortfolioPdx> valueMap = new HashMap<>();
+ LongStream.range(lowBound.get(), highBound.get()).forEach(i -> {
+ long value = ThreadLocalRandom.current().nextLong(lowBound.get(),
highBound.get());
+ valueMap.put(i, new PortfolioPdx(value));
+ });
+
logger.info("*******************************************");
logger.info(" Prepopulating the region ");
logger.info("*******************************************");
Instant start = Instant.now();
- LongStream.range(0, keyRangeToPrepopulate).forEach(i -> {
- long value = ThreadLocalRandom.current().nextLong(0,
keyRangeToPrepopulate);
- region.put(i, new PortfolioPdx(value));
- });
+
+ region.putAll(valueMap);
Review comment:
Unfortunately, I don't think we can do this whole thing in a single putAll,
if we have a lot of data. We need to *batch* up the data into multiple putAlls
- maybe 100s or 1000s per batch?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services