Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prioritise requests in order by allocating memory/workers upfront #163

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

CallumNZ
Copy link
Contributor

I found under load testing with many large requests, the memory and workers were allocated too thinly across all accepted requests, which resulted in the whole system locking up as no request could get enough to continue.

Getting memory and workers from the channel is now controlled by a mutex, but returning them remains concurrent. This ensures a requests are allocated what they need to continue in the order that they arrive.

Reference: https://github.com/GeoNet/tickets/issues/14787

Production Changes

The following production changes are required to deploy these changes:

  • None

Review

Check the box that applies to this code review. If necessary please seek help with adding a checklist guide for the reviewer.
When assigning the code review please consider the expertise needed to review the changes.

  • This is a content (documentation, web page etc) only change.
  • This is a minor change (meta data, bug fix, improve test coverage etc).
  • This is a larger change (new feature, significant refactoring etc). Please use the code review guidelines to add a checklist below to guide the code reviewer.

Code Review Guide

Insert check list here if needed.

@CallumNZ CallumNZ requested a review from junghao March 18, 2024 03:10
Copy link
Contributor

@junghao junghao left a comment

Choose a reason for hiding this comment

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

Code looks good and would improve the service's robustness.
Some coding style suggestions.

}
cm.memoryPool = mp
cm.memoryPool = memoryPool{channel: mp}
cm.memoryTotalSize = memoryTotalSize
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the math above, memoryTotalSize = memoryChunkSize * maxWorkers = maxBytes.
So can this be simplified as cm.memoryTotalSize = maxBytes ? Or there's something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's potential rounding on the division, and I want memoryTotalSize to be an exact multiple of memoryChunkSize, but yes an equivalent that's better is:
cm.memoryTotalSize = memoryChunkSize * maxWorkers

var totalMemory int64 = 0
for _, o := range objects {
var memoryForObject int64 = 0
for memoryForObject < o.Size {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since memoryChungSize is fixed, is there an easier math so we don't need a loop?

chunks := math.Ceil(float64(o.Size) / float64(cm.memoryChungSize))
totalMemoy += cm.memoryChunkSize * chunks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

woops I didn't see your code suggestion. Mine is a bit longer but no floats.

securedMemory += <-cm.memoryPool
for _, o := range objects {
var securedMemory int64 = 0
for securedMemory < o.Size {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the comment below. (Sorry I commented the code below first)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the below bit, but in this case still need a for loop to receive from the channel, so wasn't much point.

@CallumNZ CallumNZ requested a review from junghao March 19, 2024 02:28
junghao
junghao previously approved these changes Mar 19, 2024
… front

I found under load testing with many large requests, the memory and workers were allocated too thinly across all accepted requests, which resulted in the whole system locking up as no request could get enough to continue
Copy link
Contributor

@junghao junghao left a comment

Choose a reason for hiding this comment

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

Lets see how it goes :)

@sue-h-gns
Copy link
Contributor

great work!

@sue-h-gns sue-h-gns merged commit f59f70c into main Mar 19, 2024
5 checks passed
@sue-h-gns sue-h-gns deleted the concurrBug branch March 19, 2024 20:56
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.

3 participants