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

Rewrite networking code to use Tokio #42

Merged
merged 19 commits into from
Sep 30, 2019
Merged

Rewrite networking code to use Tokio #42

merged 19 commits into from
Sep 30, 2019

Conversation

caelunshun
Copy link
Member

@caelunshun caelunshun commented Aug 10, 2019

This PR includes a refactoring and partial rewrite of the networking code, based on tokio.

Motivation

The current network code is a homebrew asynchronous IO event loop based on mio. Numerous issues have appeared with this implementation, and the code is quite inefficient as well (three to five HashMap lookups when data is received or sent).

Tokio provides its own heavily optimized event loop, in addition to a much easier to use interface. Furthermore, it can extend the async IO capability beyond the TCP streams themselves; for example, the authentication request to the Mojang API in the initial handler can now be run asynchronously, which improves performance (somewhat).

Ultimately, the decision to switch to Tokio is based on performance and stability, which both are improved through the switch.

Implications

  • Server packet handling code will be unaffected.
  • The new networking code uses async/await, which was stabilized a few weeks ago and will be released in Rust stable in early to mid November. In the meantime, compiling Feather will require Rust nightly.

Fixes #34 .
Resolves #35.
Resolves #36.

@codecov
Copy link

codecov bot commented Aug 10, 2019

Codecov Report

Merging #42 into develop will increase coverage by 0.89%.
The diff coverage is 13.51%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #42      +/-   ##
===========================================
+ Coverage    60.54%   61.43%   +0.89%     
===========================================
  Files           78       77       -1     
  Lines         9284     8975     -309     
===========================================
- Hits          5621     5514     -107     
+ Misses        3663     3461     -202
Impacted Files Coverage Δ
server/src/config.rs 87.17% <ø> (-0.33%) ⬇️
server/src/lib.rs 36.86% <ø> (+0.38%) ⬆️
core/src/lib.rs 11.76% <ø> (+1.96%) ⬆️
server/src/entity/component.rs 71.42% <ø> (ø) ⬆️
core/src/network/packet/mod.rs 0% <ø> (ø) ⬆️
core/src/network/packet/implementation.rs 0% <0%> (ø) ⬆️
core/src/network/codec.rs 0% <0%> (ø)
core/src/entitymeta.rs 0% <0%> (ø) ⬆️
server/src/main.rs 0% <0%> (ø) ⬆️
server/src/io/worker.rs 0% <0%> (-23.88%) ⬇️
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e51cc5...0082762. Read the comment docs.

@caelunshun caelunshun added this to the 0.5 milestone Aug 16, 2019
caelunshun added a commit that referenced this pull request Sep 4, 2019
This is a hotfix for #110. It is quick and dirty,
and pull request #42 will include a proper fix
for this issue.

Resolves #110.
@caelunshun caelunshun mentioned this pull request Sep 5, 2019
5 tasks
@caelunshun
Copy link
Member Author

Functionality is complete. Only thing left is to fix tests and clippy.

@caelunshun caelunshun marked this pull request as ready for review September 30, 2019 02:00
@caelunshun caelunshun merged commit c950e2f into develop Sep 30, 2019
@caelunshun caelunshun deleted the tokio branch September 30, 2019 03:06
cheako pushed a commit to cheako/feather that referenced this pull request Jan 4, 2020
# Summary
* Replaced the mio-based IO event loop with a Tokio task
* Rewrote packet encoding/decoding code, should now be more efficient
* Converted `Packet` to write to `BytesMut` instead of `ByteBuf`; `ByteBuf` removed

# Motivation
The current network code is a homebrew asynchronous IO event loop based on mio. Numerous issues have appeared with this implementation, and the code is quite inefficient as well (three to five HashMap lookups when data is received or sent).

Tokio provides its own heavily optimized event loop, in addition to a much easier to use interface. Furthermore, it can extend the async IO capability beyond the TCP streams themselves; for example, the authentication request to the Mojang API in the initial handler can now be run asynchronously, which improves performance (somewhat).

Ultimately, the decision to switch to Tokio is based on performance and stability, which both are improved through the switch.

# Implications
* Server packet handling code will be unaffected.
* The new networking code uses async/await, which was stabilized a few weeks ago and will be released in Rust stable in early to mid November. In the meantime, compiling Feather will require Rust nightly.

Fixes feather-rs#34 .
Resolves feather-rs#35.
Resolves feather-rs#36.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant