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

added a 100ms sleep to the keep alive system to prevent it from having excessive cpu usage #117

Merged
merged 5 commits into from
Nov 10, 2024

Conversation

AnonymousBit0111
Copy link

No description provided.

@0xnim
Copy link

0xnim commented Nov 5, 2024

The keepalive system should be 15sec, 15000ms

@Sweattypalms
Copy link
Member

^ There is no point checking keepalive every 100ms. Since keepalive typically runs every 30 seconds, checking every 15 seconds ensures we catch all players' status even if they join right after a check, while still being far more efficient than checking every 100ms.

@@ -84,10 +85,11 @@ impl System for KeepAliveSystem {
if let Err(e) = state.broadcast(&packet, broadcast_opts).await {
error!("Error sending keep alive packet: {}", e);
};

// TODO, this should be configurable as some people may have bad network so the clients may end up disconnecting from the server moments before the keep alive is sent
Copy link
Member

Choose a reason for hiding this comment

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

15 seconds delay means the client gets 2 chances. The default timeout for keepalive is 30 seconds.

Copy link
Contributor

@Skullians Skullians left a comment

Choose a reason for hiding this comment

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

Did you mean to type 30?
currently says 39

Copy link
Contributor

@Skullians Skullians left a comment

Choose a reason for hiding this comment

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

LGTM

  • professional rust dev

@AnonymousBit0111
Copy link
Author

#119 should be fixed now can you please check @0xnim , I'm not sure how to simulate a client timing out

@0xnim
Copy link

0xnim commented Nov 9, 2024

@AnonymousBit0111 another issue has occured, only a single player can join

// TODO Kick player
}

let result = state.universe.get_mut::<IncomingKeepAlivePacket>(conn_id);
Copy link

Choose a reason for hiding this comment

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

This is where the problem happens I'm guessing.

Comment on lines +33 to +53

if result.is_err() {
let err = result.as_ref().err().unwrap();
if matches!(err, ECSError::ComponentTypeNotFound) {
state
.universe
.add_component(conn_id, IncomingKeepAlivePacket { id: self.id })?;
let mut last_received_keep_alive = state.universe.get_mut(conn_id)?;
*last_received_keep_alive = self;
} else {
warn!(
"Failed to get or create <IncomingKeepAlive> component: {:?}",
err
);
return Err(crate::errors::NetError::ECSError(result.err().unwrap()));
}
} else {
*last_keep_alive = KeepAlive::from(self.id);
let mut last_received_keep_alive: ComponentRefMut<'_, IncomingKeepAlivePacket> =
result.unwrap();

*last_received_keep_alive = self;
Copy link
Member

Choose a reason for hiding this comment

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

Why not just do a match statement?

match result {
    Ok(component) => {
        // ...
    },
    Err(e) => {
        // ...
    }
}

Copy link

Choose a reason for hiding this comment

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

doesnt fix the problem of the error?

Copy link

Choose a reason for hiding this comment

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

state.universe.get_mut::<IncomingKeepAlivePacket>(conn_id)

is the culprit

Copy link

Choose a reason for hiding this comment

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

Can this be a deadlock from dashmap?

Copy link
Member

Choose a reason for hiding this comment

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

If something stupid is being done, probably. I haven't read the code in too much depth, but this shouldn't be the case.

Copy link
Author

Choose a reason for hiding this comment

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

it wasnt, I think the error system is a bit inconsistent, I expected only ComponentTypeNotFound, but also got ComponentRetrievalError, when they're both reporting what should be the same error since the IncomingKeepAlive hasn't been created yet, I've fixed this in #122

@0xnim 0xnim mentioned this pull request Nov 10, 2024
@Sweattypalms Sweattypalms merged commit 0842a7b into ferrumc-rs:rewrite/v3 Nov 10, 2024
3 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.

4 participants