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

Examples for integration with tokio #205

Closed
dylanede opened this issue Apr 27, 2018 · 18 comments
Closed

Examples for integration with tokio #205

dylanede opened this issue Apr 27, 2018 · 18 comments

Comments

@dylanede
Copy link

I have an existing crate built upon tokio that I want to use within a web server. It makes heavy use of tokio timers and spawn. There don't appear to be any examples in actix-web of how to integrate tokio-based code with the tokio event loops underpinning actix. I'm also not sure how I would go about getting a reactor handle to call spawn on in actix-web.

@ms-ati
Copy link

ms-ati commented May 17, 2018

Yes! Same question, specifically for making AWS calls via the Rusoto crate, which is based on Tokio reactor as well. How can we get to run on same reactor as the Actix server?

@fafhrd91
Copy link
Member

fafhrd91 commented May 17, 2018

maybe you can get handle Arbiter::handle() and convert it to tokio handle?

as I understand Rusoto uses hyper 0.11, which is tokio-core based. Arbiter::handle() is tokio-core'a handle

@fafhrd91
Copy link
Member

I will migrate actix to Tokio in next version. actix 0.6 and actix-web 0.7

@nayato
Copy link

nayato commented May 18, 2018

@fafhrd91 is it there already in terms of maturity / stability / tuning to make the switch?

@fafhrd91
Copy link
Member

@nayato I don’t know. But I hope with local executor we won’t loose performance. On other hand we should get some boost with simd in 1.27

@nayato
Copy link

nayato commented May 18, 2018

@fafhrd91 I don't think there's anything magic about SIMD support. That is unless it is explicitly employed in HTTP parsing, unmasking WS payload, etc. Am I missing smth? :)

@fafhrd91
Copy link
Member

you are not, but with stable simd we can start using simd :)

@vmalloc
Copy link
Contributor

vmalloc commented May 24, 2018

I'm also interested in examples on how to integrate tokio (especially tokio-proto) with actix and actix-web. If anyone has pointers or working examples that would be greatly appreciated

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 3, 2018

for current stable 0.6 release only way to integration with tokio-core is Handle.
Handle is available from arbiter Arbiter::handler()

master uses tokio, so tokio::spawn() and Handle::default() should be enough.

@fafhrd91 fafhrd91 closed this as completed Jun 3, 2018
@rocallahan
Copy link

Unfortunately mixing actix-web 0.7 and old-tokio (tokio-core) crates is very hard because old/new-tokio interop depends on constructing a tokio_core::reactor::Core, getting a tokio_core::reactor::Handle and calling new_tokio_handle() on it to get a tokio::reactor::Handle. But as far as I can tell you can't start actix with just a tokio::reactor::Handle.

@DoumanAsh
Copy link
Contributor

You're not supposed to mix old tokio at all, it would be the best to get rid of it

@rocallahan
Copy link

Sure. Unfortunately, a lot of existing crates haven't been updated to new tokio yet.

@DoumanAsh
Copy link
Contributor

Maybe it is sad that these libraries are abandoned but no one has plans for actix to support tokio-core precisely because it is deprecated.

@rocallahan
Copy link

Yeah, that's fine.

@timglabisch
Copy link

is it fine to run actix and another tokio runtime side by side? i dont want to mix them.

@fafhrd91
Copy link
Member

pretty obvious https://docs.rs/actix-rt/1.0.0/actix_rt/struct.System.html#method.run_in_tokio

@thangchung
Copy link

I have seen that with new actix-web, we have actix_web::rt::System::with_tokio_rt to run the tokio runtime. But I haven't found any example for how to use it. Could anyone give us an example to use actix-web with tokie?

@robjtede
Copy link
Member

See #1283.

@actix actix locked as off-topic and limited conversation to collaborators Mar 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants