Giter Site home page Giter Site logo

Comments (9)

seanmonstar avatar seanmonstar commented on April 28, 2024

The parsing is happening here, and that code is run inside the hyper acceptor task.

We can't assume the user of the library wants to spawn a new task per connection (most reasonable servers would likely want to use a task pool with a limit).


What if a handler were to spawn a task before calling incoming.next(). That should move the parsing into a separate task, right? Can that be safely/easily done? I haven't looked too hard.

from hyper.

reem avatar reem commented on April 28, 2024

It would require Arc<Mutex<Incoming>> but should work, so that is one workaround.

from hyper.

seanmonstar avatar seanmonstar commented on April 28, 2024

Alternatively, the Incoming could return some sort of "request/response" future, so that once it's been passed to a destination task, the parsing could happen there.

from hyper.

seanmonstar avatar seanmonstar commented on April 28, 2024

The more I think about it, the more I like returning a Future<(Request, Response<Fresh>)>.

from hyper.

reem avatar reem commented on April 28, 2024

That requires allocating a new proc and task for each incoming Request, which basically defeats the purpose.

Maybe we could work around the proc when unboxed closures are moved into libs, but we would still need a new task.

from hyper.

seanmonstar avatar seanmonstar commented on April 28, 2024

No it doesn't. There is Future::from_fn, which does not execute on a new task.

from hyper.

seanmonstar avatar seanmonstar commented on April 28, 2024

This allows the parsing to be deferred until the Future is on whichever task will be handling the Request, and reduces the overhead of an Arc and Mutex.

from hyper.

reem avatar reem commented on April 28, 2024

You are right, I was thinking of Future::spawn. We still have to allocate for a proc(), but that could be avoided if we defined our own Future type which stored F: FnOnce() -> T or a more specialized type that stored the NetworkStream and an fn(Box<NetworkStream>) -> (Request, Response<Fresh>) so that we get static dispatch and can avoid unnecessary allocation.

Basically we should do the minimum possible work between "get a connection" and "yield to incoming.next", then allow all further processing to be done with the returned handle, so it can be done in another task.

The contention we'd get from locking/unlocking a mutex at 100s of concurrent connections will almost definitely hurt a lot.

Related data point: using a TaskPool in Iron instead of regular spawn sped up Iron by 80%.

from hyper.

seanmonstar avatar seanmonstar commented on April 28, 2024

fixed with #110

from hyper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.