-
Notifications
You must be signed in to change notification settings - Fork 182
TODO: throttle on async validators #755
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
Conversation
Hi @lla-dane, This looks like a solid fix for the async validator throttling TODO, but there's a critical issue where the default parameter |
Hey @paschal533
Did this, added a
For this, added the concurrency checker part in the original Does this work @paschal533 ? |
79620cf
to
0731202
Compare
@lla-dane - Looking good! I'm concerned about copying so much code directly from |
This is a great approach. this definitely fixes the main issue, and integrating the concurrency checking into the existing |
async def _run_async_validator( | ||
self, | ||
func: AsyncValidatorFn, | ||
msg_forwarder: ID, | ||
msg: rpc_pb2.Message, | ||
results: list[bool], | ||
) -> None: | ||
async with self._validator_semaphore: | ||
result = await func(msg_forwarder, msg) | ||
results.append(result) |
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.
@pacrob: separated the run_async_validator
method to a separate class method as you suggested. Now there is only this much duplicated code from the pubsub.py
in the tests:
async def mock_run_async_validator(
self,
func: AsyncValidatorFn,
msg_forwarder: ID,
msg: rpc_pb2.Message,
results: list[bool],
) -> None:
async with self._validator_semaphore:
async with lock:
state["concurrency_counter"] += 1
if state["concurrency_counter"] > state["max_observed"]:
state["max_observed"] = state["concurrency_counter"]
try:
result = await func(msg_forwarder, msg)
results.append(result)
finally:
async with lock:
state["concurrency_counter"] -= 1
@pacrob : Did a few changes as you suggested here. Please see if everything is alright. |
libp2p/pubsub/pubsub.py
Outdated
async def run_async_validator(func: AsyncValidatorFn) -> None: | ||
result = await func(msg_forwarder, msg) | ||
results.append(result) | ||
async with self._validator_semaphore: | ||
result = await func(msg_forwarder, msg) | ||
results.append(result) |
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.
Since you extracted the logic out, this code can be deleted, right?
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.
My bad, forgot to remove this. Now removed!!
e3bc7bb
to
3ef5fe8
Compare
Fixed a
TODO: Implement throttle on async validators
inlibp2p/pubsub/pubsub.py::validate_msg()
.Used semaphores to limit concurrency while running concurrent async_validators: