Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upConsider promoting DirectService to Service #136
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Do we have other examples of services that cannot drive an inner As a secondary concern, I don't like |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
On a tangential note, I think the current contract of "you must call |
This comment has been minimized.
This comment has been minimized.
That's probably what should happen. I don't think a panic would be good. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
What you say all makes sense. However, my concern is that we are overloading |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
I updated the main issue with a suggested roadmap to implement this change while validating it along the way:
|
carllerche
assigned
hawkw
Jan 12, 2019
This comment has been minimized.
This comment has been minimized.
|
The next steps are to make the change across the tower stack in a branch. This is the same process we took for |
carllerche commentedDec 13, 2018
•
edited
The
DirectServicetrait (introduced in #118) is an alternate version ofServicethat 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
Servicetrait.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_serviceas needed. Because of this, there are service implementations that driven (requirepoll_serviceto be called) and there are service implementations that are buffered (requests get dispatched on a channel to another task). These services do not requirepoll_serviceto 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
DirectServicewithServiceand useCloneas 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: Serviceand thatTis cloned into the router's response future.T::poll_readyis called by the response future. Services that are unable to callpoll_readywill all most likely take aT: Service + Clone.So, the proposal is to make
ServicewhatDirectServiceis today.Serviceimplementations likeBufferwould have no-oppoll_serviceandpoll_closeimplementations.Complexity
The other con is that implementing
Servicebecomes more complicated. This is a real drawback, but I believe it can be mitigated by providing utilities for common patterns:service_fnfor 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->Servicebut keep it in thetower-direct-servicecrate.tower_direct_service::Serviceinstead oftower_service::Servicetower_service::Servicewithtower_direct_service::Serviceand releasetower-service0.3.Refs #137