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

actix-rt: Make the process of running System in existing Runtime more clear #173

Merged
merged 5 commits into from Sep 6, 2020
Merged

actix-rt: Make the process of running System in existing Runtime more clear #173

merged 5 commits into from Sep 6, 2020

Conversation

popzxc
Copy link
Member

@popzxc popzxc commented Aug 6, 2020

PR Type

Other (Usability enhancement)

PR Checklist

Check your PR fulfills the following:

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt

Overview

When I first tried to start the actix-web server using an existing tokio Runtime, I honestly found the interface a bit unfriendly.

In an attempt to make other folks' life easier I did the following:

  • Added doc-comments with an example and a note about Arbiters still using their own Runtime objects.
  • Added a new method which is less flexible but simpler to use to attach a System to a given Runtime.

These changes aren't breaking and hopefully useful.

@codecov
Copy link

codecov bot commented Aug 6, 2020

Codecov Report

Merging #173 into master will decrease coverage by 0.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #173      +/-   ##
==========================================
- Coverage   60.20%   60.13%   -0.07%     
==========================================
  Files          73       73              
  Lines        4784     4789       +5     
==========================================
  Hits         2880     2880              
- Misses       1904     1909       +5     
Impacted Files Coverage Δ
actix-rt/src/builder.rs 45.00% <0.00%> (ø)
actix-rt/src/system.rs 51.16% <0.00%> (-6.74%) ⬇️

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 88d99ac...11b2d2b. Read the comment docs.

@JohnTitor JohnTitor requested review from a team August 7, 2020 09:17
actix-rt/src/system.rs Outdated Show resolved Hide resolved
actix-rt/Cargo.toml Outdated Show resolved Hide resolved
/// let rest_operations = run_application();
/// System::attach_to_tokio(runtime, "actix-main-system", rest_operations);
/// ```
pub fn attach_to_tokio<Fut, R>(
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of this function, making it much simpler to host actix in an existing tokio runtime.

Are there alternate designs for the rest_operations idea worth discussing? I seem to recall in the past just joining and awaiting the actix LocalSet with any other long running tasks. This approach feels more opinionated and less extensible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I've attempted several other approaches, but found them not as convenient because of the following factors:

  • LocalSet occupies current thread for System to run;
  • Future, obtained via LocalSet is not Send.

Thus, returning a future from this function (instead of blocking the runtime inside) makes the user-side code not really intuitive.

As an alternative approach, we may make rest_operations a function rather than a future, but IMHO it's less flexible: if you have an async function, you can get a future by simply calling it, and at the same time you can get a future without an additional function (e.g. using an async { } block).

Or do you have an idea how to get rid of the rest_operations argument without complications on the caller site?

Copy link
Member

Choose a reason for hiding this comment

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

This feels like we're moving into a simpler Node.js style <req, res> or Koa's ctx and I'm all for it. I'd love to have Actix just be the web layer on top of default Tokio.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is similar to what @fafhrd91 was describing too about the actix-net features.

actix-rt/src/system.rs Show resolved Hide resolved
@popzxc popzxc requested a review from robjtede August 10, 2020 12:55
@robjtede robjtede requested review from a team August 10, 2020 13:03
@popzxc
Copy link
Member Author

popzxc commented Aug 14, 2020

@robjtede Can you please clarify how long it usually takes for a PR to get reviewed?

@robjtede
Copy link
Member

@popzxc I'm in favor of these changes. I'd like someone else from @actix/contributors team to chime in before we get it merged though.

@popzxc
Copy link
Member Author

popzxc commented Aug 14, 2020

I see, thanks! Let's wait then :)

@popzxc
Copy link
Member Author

popzxc commented Sep 6, 2020

@robjtede I don't want to be annoying, but it seems that nobody else want to review this PR.

@Neopallium
Copy link
Member

@popzxc I just looked over the changes. I think it would be good to add a test for this new function. Also the PR will need to be rebased against master. Other then that it looks good.

Ping me later if you need another review.

@popzxc
Copy link
Member Author

popzxc commented Sep 6, 2020

I think it would be good to add a test for this new function

@Neopallium Isn't provided doc-test enough? If not, I'm not exactly sure what kind of test is required, could you provide an approximate form of how do you see it?

@Neopallium
Copy link
Member

I am not sure if doc-tests are run. checking now.

@popzxc
Copy link
Member Author

popzxc commented Sep 6, 2020

Also after rebase there seems to be some inherited clippy warnings. Not sure if I have to fix them as part of this PR, as some of them don't even belong to the actix-rt crate.

@Neopallium
Copy link
Member

yeah. I see those. I don't think they should be fixed in this PR. I can't merge this PR, but I can submit a review for you.

The Doc-tests seem to only check if the doc example code compiles. A test would be good to make sure that attaching to an existing tokio-runtime still works (all normal tokio & actix tasks still run). I am not sure if that would be easy to verify in a test.

@Neopallium
Copy link
Member

@popzxc I am fixing the clippy errors in PR #187

@robjtede Is there anything else blocking this PR?

@Neopallium Neopallium mentioned this pull request Sep 6, 2020
4 tasks
@robjtede
Copy link
Member

robjtede commented Sep 6, 2020

Is there anything else blocking this PR?

@Neopallium nope, many thanks for your input here. Once the rebased checks pass we'll merge.

@robjtede robjtede merged commit b7a9cb7 into actix:master Sep 6, 2020
@popzxc popzxc deleted the friendly-tokio branch September 6, 2020 10:01
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.

None yet

4 participants