-
Notifications
You must be signed in to change notification settings - Fork 704
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
sc-executor: Increase maximum instance count #1856
Conversation
It was reported that the maximum instance count of `32` isn't enough. By default `wasmtime` uses an instance count of `1000`. So, it should be safe to increase the instance count to `1000`.
Should fix: moonbeam-foundation/moonbeam#2509 |
Thank you Basti. |
Hmm yeah, actually this is already failing :P I had thought that this is only about reserved memory. |
Changes the value. I probably should improve this even more and just let it block when we try to allocate more than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, ultimately it would be best to have a low limit (we most likely don't need to support more parallel executor instances than the machine has hardware threads; otherwise that'll just lower the overall throughput and increase the risk of running out of memory) and have it block if we have too many instances running in parallel.
@@ -22,7 +22,7 @@ use std::str::FromStr; | |||
/// Parameters used to config runtime. | |||
#[derive(Debug, Clone, Args)] | |||
pub struct RuntimeParams { | |||
/// The size of the instances cache for each runtime. The values higher than 256 are illegal. | |||
/// The size of the instances cache for each runtime. The values higher than 32 are illegal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. what about a public const
for 32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was thinking about this as well. But then we would need to put this to some random place again or import another crate. So, I decided against this for now.
if *counter + 1 < MAX_INSTANCE_COUNT { | ||
*counter += 1; | ||
} else { | ||
self.wait_for_instance.wait(&mut counter); | ||
*counter += 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a possibility for a race condition here?
Consider the following scenario:
- Thread
A
acquires the lock. Findscounter == MAX_INSTANCE_COUNT
. Waits in the counter condvar. - Some other thread (in the
drop
above) decrements the counter value and callsnotify_one
(note that we release the lock before sending the notification) - Before thread
A
is woken up another threadB
grabs the lock and the counter goes back toMAX_INSTANCE_COUNT
. - Thread
A
now receives the notification and acquires the lock. Increments the counter to be equal toMAX_INSTANCE_COUNT + 1
Maye this is safer?
while *counter >= MAX_INSTANCE_COUNT {
self.wait_for_instance.wait(&mut counter);
}
*counter += 1;
Or maybe release the lock in the drop
after the notification is sent. But I don't know if is guaranteed that no other thread (not one in the wait queue) can grab the lock (alter the counter and release the lock) before the notified one is started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, actually, I think you are right here. Yeah, 👍 to just have a loop here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test would be nice. (:
Co-authored-by: Koute <koute@users.noreply.github.com>
Co-authored-by: Koute <koute@users.noreply.github.com>
…ease-instance-count
Changes the maximum instances count for `wasmtime` to `64`. It also allows to only pass in maximum `32` for `--max-runtime-instances` as `256` was way too big. With `64` instances in total and `32` that can be configured in maximum, there should be enough space to accommodate for extra instances that are may required to be allocated adhoc. --------- Co-authored-by: Koute <koute@users.noreply.github.com>
Changes the maximum instances count for
wasmtime
to64
. It also allows to only pass in maximum32
for--max-runtime-instances
as256
was way too big. With64
instances in total and32
that can be configured in maximum, there should be enough space to accommodate for extra instances that are may required to be allocated adhoc.