Skip to content

Fix default worker capacity#1455

Merged
jfallows merged 5 commits intoaklivity:developfrom
akrambek:bug/resource-allocation
Apr 11, 2025
Merged

Fix default worker capacity#1455
jfallows merged 5 commits intoaklivity:developfrom
akrambek:bug/resource-allocation

Conversation

@akrambek
Copy link
Contributor

@akrambek akrambek commented Apr 10, 2025

Fix #1456

@akrambek akrambek changed the title FIx default worker capacity Fix default worker capacity 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the use of Integer.highestOneBit(...) above, we can remove this, agree?

@jfallows jfallows merged commit 5877f83 into aklivity:develop Apr 11, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Miscalculating default worker capacity

2 participants