-
Notifications
You must be signed in to change notification settings - Fork 282
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
Consider promoting DirectService to Service #136
Comments
Do we have other examples of services that cannot drive an inner As a secondary concern, I don't like |
To be clear, poll_service and others are still called, but they are called on the cloned handle in the Response future. This is already the strategy used with poll_ready. If you know cases in which this strategy does not work, let’s discuss them. |
That implies that you can My concern is more the opportunity for accidental misuse here. For example, consider I also think it's unfortunate to expose |
On a tangential note, I think the current contract of "you must call |
That's probably what should happen. I don't think a panic would be good. |
|
What you say all makes sense. However, my concern is that we are overloading |
Following much discussion, some perhaps more refined thoughts: Tower assumes that if it clones a I'm not necessarily arguing for Another tangentially related point that came up was that Tower assumes that cloning a |
I updated the main issue with a suggested roadmap to implement this change while validating it along the way:
|
The next steps are to make the change across the tower stack in a branch. This is the same process we took for |
Closing as this avenue is no longer being considered. |
The
DirectService
trait (introduced in #118) is an alternate version ofService
that is being experimented with. It provides the necessary hooks to "drive" a service's internal state machine forward. This allows avoiding to have to spawn new tasks to power service implementations.We should consider whether or not this trait should be promoted to be the primary
Service
trait.Driven vs. buffered
When introducing
DirectService
, we extensively discussed whether or not the functionality should just be provided byService
. We concluded that it should not. The primary reason is that middleware is not always able to drive the inner service. For example, a router cannot effectively callpoll_service
as needed. Because of this, there are service implementations that driven (requirepoll_service
to be called) and there are service implementations that are buffered (requests get dispatched on a channel to another task). These services do not requirepoll_service
to be called. Initially, we could not figure out a good way to implement middleware that could indicate which kind of service it wanted, so we opted for two completely separate traits.It occurred to me that we could combine
DirectService
withService
and useClone
as an indicator of whether or not the service is driven vs. buffered. The router must already acceptT: Service + Clone
. The strategy taken is, when a request comes in, the request is routed to an innerT: Service
and thatT
is cloned into the router's response future.T::poll_ready
is called by the response future. Services that are unable to callpoll_ready
will all most likely take aT: Service + Clone
.So, the proposal is to make
Service
whatDirectService
is today.Service
implementations likeBuffer
would have no-oppoll_service
andpoll_close
implementations.Complexity
The other con is that implementing
Service
becomes more complicated. This is a real drawback, but I believe it can be mitigated by providing utilities for common patterns:service_fn
for easily defining leaf services.For example, basic logging could be implemented as:
And more complicated:
Roadmap
The promotion could be done in a few steps.
DirectService
->Service
but keep it in thetower-direct-service
crate.tower_direct_service::Service
instead oftower_service::Service
tower_service::Service
withtower_direct_service::Service
and releasetower-service
0.3.Refs #137
The text was updated successfully, but these errors were encountered: