-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We want to track of sizes of messages sent from `PeerActor` to `PeerManagerActor`. We will stop reading from given `PeerActor` once we reach the limit. To achieve this a new type `ActixMessageWrapper` was introduced. It wraps around messages sent to peer, and contains metadata needed for stat counting. This is a draft: - [x] Add a wrapper for sending messages from`PeerActor` to `PeerManagerActor` - [x] Modify `PeerActor` to use - [x] Add a wrapper for reply's to the above messages (wating for `DeepSizeOf`) - [ ] Wait for `DeepSizeOf` (another PR) - [ ] Add a wrapper for messages to Peer - for example for routing (another PR) - [ ] Add a wrapper for messages to EdgeVerifierActor - for example for routing (another PR) - [ ] Add a wrapper for messages to RoutingTableActor - for example for routing (another PR) - [ ] Add a wrapper for messages to ClientActor - for example for routing (another PR) - [ ] Extensions to `performance_stats` to track per thread limits (another PR) - [ ] Extension to track bandwidth (another PR) This PR is based on, not yet merged, #4927 Resolves #5155 Blocked by Aeledfyr/deepsize#18
- Loading branch information
Showing
7 changed files
with
203 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use actix::dev::MessageResponse; | ||
use actix::Message; | ||
use near_rate_limiter::{ThrottleController, ThrottleToken}; | ||
|
||
// Wrapper around Actix messages, used to track size of all messages sent to PeerManager. | ||
// TODO(#5155) Finish implementation of this. | ||
|
||
#[allow(unused)] | ||
/// TODO - Once we start using this `ActixMessageWrapper` we will need to make following changes | ||
/// to get this struct to work | ||
/// - Add needed decorators. Probably `Debug`, `Message` from Actix, etc. | ||
/// - Add two rate limiters (local per peer, global one) | ||
/// - Any other metadata we need debugging, etc. | ||
pub struct ActixMessageWrapper<T> { | ||
msg: T, | ||
throttle_token: ThrottleToken, | ||
} | ||
|
||
impl<T> ActixMessageWrapper<T> { | ||
pub fn new_without_size(msg: T, throttle_controller: ThrottleController) -> Self { | ||
Self { msg, throttle_token: ThrottleToken::new(throttle_controller, 0) } | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn into_inner(mut self) -> T { | ||
return self.msg; | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn take(mut self) -> (T, ThrottleToken) { | ||
return (self.msg, self.throttle_token); | ||
} | ||
} | ||
|
||
impl<T: Message> Message for ActixMessageWrapper<T> { | ||
type Result = ActixMessageResponse<T::Result>; | ||
} | ||
|
||
#[derive(MessageResponse)] | ||
pub struct ActixMessageResponse<T> { | ||
msg: T, | ||
/// Ignore the warning, this code is used. We decrease counters `throttle_controller` when | ||
/// this attribute gets dropped. | ||
#[allow(unused)] | ||
throttle_token: ThrottleToken, | ||
} | ||
|
||
impl<T> ActixMessageResponse<T> { | ||
#[allow(unused)] | ||
pub fn new(msg: T, throttle_token: ThrottleToken) -> Self { | ||
Self { msg, throttle_token } | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn into_inner(mut self) -> T { | ||
return self.msg; | ||
} | ||
|
||
#[allow(unused)] | ||
pub fn take(mut self) -> (T, ThrottleToken) { | ||
return (self.msg, self.throttle_token); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod message_wrapper; |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.