Fix default worker capacity#1455
Merged
jfallows merged 5 commits intoaklivity:developfrom Apr 11, 2025
Merged
Conversation
jfallows
requested changes
Apr 10, 2025
| long totalBufferCapacity = numberOfCores * (bufferCapacity + budgetBufferCapacity + eventsBufferCapacity); | ||
| int newWorkersCapacity = (int) (maxAllowedForBuffers / totalBufferCapacity); | ||
| long budgetBufferCapacity = BudgetsLayout.SIZEOF_BUDGET_ENTRY; | ||
| long totalBufferCapacity = numberOfCores * (bufferCapacity + budgetBufferCapacity); |
Contributor
There was a problem hiding this comment.
I realized that although we default workers to available processors, the calculation should actually be based on workers, not numberOfCores.
So, we actually only need osBean for getTotalMemorySize().
For workers, we would do this instead.
int workers = ENGINE_WORKERS.getAsInt(config);
Also, for clarity suggest we do the following:
int workerBufferCapacity = slotCapacity + slotCapacity + budgetBufferCapacity;
int totalBufferCapacity = workerBufferCapacity * workers;
Comment on lines
+390
to
+395
| long maxAllowedForMemory = (long) (percentMemory * totalMemorySize) - totalEventsBufferCapacity; | ||
|
|
||
| Path directory = Paths.get(ENGINE_DIRECTORY.get(config)); | ||
| long usableDiskSpace = directory.toFile().getUsableSpace(); | ||
|
|
||
| long maxAllowedForBuffers = Math.min(maxAllowedForMemory, usableDiskSpace); |
Contributor
There was a problem hiding this comment.
Suggested change
| long maxAllowedForMemory = (long) (percentMemory * totalMemorySize) - totalEventsBufferCapacity; | |
| Path directory = Paths.get(ENGINE_DIRECTORY.get(config)); | |
| long usableDiskSpace = directory.toFile().getUsableSpace(); | |
| long maxAllowedForBuffers = Math.min(maxAllowedForMemory, usableDiskSpace); | |
| long maxMemoryBufferCapacity = (long) (percentMemory * totalMemorySize) - totalEventsBufferCapacity; | |
| Path directory = Paths.get(ENGINE_DIRECTORY.get(config)); | |
| long usableDiskSpace = directory.toFile().getUsableSpace() | |
| double percentDisk = ENGINE_DISK_PERCENTAGE.get(config); | |
| long maxDiskBufferCapacity = (long) (percentDisk * usableDiskSpace); | |
| long maxBufferCapacity = Math.min(maxMemoryBufferCapacity, maxDiskBufferCapacity); |
| int newWorkersCapacity = (int) (maxAllowedForBuffers / totalBufferCapacity); | ||
| long budgetBufferCapacity = BudgetsLayout.SIZEOF_BUDGET_ENTRY; | ||
| long totalBufferCapacity = numberOfCores * (bufferCapacity + budgetBufferCapacity); | ||
| int newWorkersCapacity = (int) (maxAllowedForBuffers / totalBufferCapacity); |
Contributor
There was a problem hiding this comment.
Suggested change
| int newWorkersCapacity = (int) (maxAllowedForBuffers / totalBufferCapacity); | |
| int newWorkersCapacity = Integer.highestOneBit((int) (maxBufferCapacity / totalBufferCapacity)); |
Comment on lines
+403
to
+413
| int roundedUp = findNextPositivePowerOfTwo(newWorkersCapacity); | ||
| long requiredForRoundedUp = (long) roundedUp * totalBufferCapacity; | ||
|
|
||
| if (requiredForRoundedUp <= maxAllowedForBuffers) | ||
| { | ||
| newWorkersCapacity = roundedUp; | ||
| } | ||
| else | ||
| { | ||
| newWorkersCapacity = Math.max(1, roundedUp >> 1); | ||
| } |
Contributor
There was a problem hiding this comment.
With the use of Integer.highestOneBit(...) above, we can remove this, agree?
jfallows
approved these changes
Apr 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #1456