Commit Graph

33 Commits

Author SHA1 Message Date
Sean McArthur db2f0ecfb3
Introduce tower-load-shed (#204)
Provides a middleware that immediately fails any request if the
underlying service isn't ready yet. This is useful when used in
conjunction with `InFlightLimit` or others, so that requests are
rejected immediately, instead of keeping track of extra pending
requests.
2019-03-20 15:48:10 -07:00
Carl Lerche 263c680ea6 Remove tower-watch (#200) 2019-03-19 18:18:59 -07:00
Carl Lerche 92f4a0cb72
Rename tower-util -> tower (#197) 2019-03-15 10:53:19 -07:00
Carl Lerche acda5a75b9
Initial introduction of tower-service-util (#193) 2019-03-14 11:27:36 -07:00
Carl Lerche 794aa44c4b
Create subdir for tower crate (#182) 2019-03-06 07:54:39 -08:00
Lucio Franco c5d70481bd
layer: Add `tower-layer` and the `Layer` trait (#163)
This change introduces the new `tower-layer` crate and the foundational `Layer` trait to go along with it. This trait allows one to easily compose a set of `Service`s that take an inner service. These services only modify the request/response. This also provides the `Layer` implementation for many of the tower crates.
2019-02-27 15:28:42 -05:00
Carl Lerche 25eb52153d
Remove DirectService (#160) 2019-02-16 10:21:59 -08:00
Carl Lerche 1b8dc7149a
Remove tower-router (#153)
The current implementation is not ideal and there is no plan to work on
it in the near term.
2019-01-28 12:15:13 -08:00
Lucio Franco e6a3f76707 Add initial base tower crate (#149)
This adds the inital base tower crate, as of right now it contains
nothing and is only needed to ensure that cargo workspaces can
properly compile with rust 1.32.

See also rust-lang/rust#57524. Previously, the examples were
never even compiled.
2019-01-19 12:47:03 -05:00
Jon Gjengset 9bae225918 Add the DirectService trait (#118)
This patch adds the `DirectService` trait, and related implementations
over it in `tower_balance` and `tower_buffer`. `DirectService` is
similar to a `Service`, but must be "driven" through calls to
`poll_service` for the futures returned by `call` to make progress.

The motivation behind adding this trait is that many current `Service`
implementations spawn long-running futures when the service is created,
which then drive the work necessary to turn requests into responses. A
simple example of this is a service that writes requests over a
`TcpStream` and reads responses over that same `TcpStream`. The
underlying stream must be read from to discover new responses, but there
is no single entity to drive that task. The returned futures would share
access to the stream (and worse yet, may get responses out of order),
and then service itself is not guaranteed to see any more calls to it as
the client is waiting for its requests to finish.

`DirectService` solves this by introducing a new method, `poll_service`,
which must be called to make progress on in-progress futures.
Furthermore, like `Future::poll`, `poll_service` must be called whenever
the associated task is notified so that the service can also respect
time-based operations like heartbeats.

The PR includes changes to both `tower_balance::Balance` and
`tower_buffer::Buffer` to add support for wrapping `DirectService`s. For
`Balance` this is straightforward: if the inner service is a `Service`,
the `Balance` also implements `Service`; if the inner service is a
`DirectService`, the `Balance` is itself also a `DirectService`. For
`Buffer`, this is more involved, as a `Buffer` turns any `DirectService`
*into* a `Service`. The `Buffer`'s `Worker` is spawned, and will
therefore drive the wrapped `DirectService`.

One complication arises in that `Buffer<T>` requires that `T: Service`,
but you can safely construct a `Buffer` over a `DirectService` per the
above. `Buffer` works around this by exposing

```rust
impl Service for HandleTo<S> where S: DirectService {}
```

And giving out `Buffer<HandleTo<S>>` when the `new_directed(s: S)`
constructor is invoked. Since `Buffer` never calls any methods on the
service it wraps, `HandleTo`'s implementation just consists of calls to
`unreachable!()`.

Note that `tower_buffer` now also includes a `DirectedService` type,
which is a wrapper around a `Service` that implements `DirectService`.
In theory, we could do away with this by adding a blanket impl:

```rust
impl<T> DirectedService for T where T: Service {}
```

but until we have specialization, this would prevent downstream users
from implementing `DirectService` themselves.

Finally, this also makes `Buffer` use a bounded mpsc channel, which
introduces a new capacity argument to `Buffer::new`.

Fixes #110.
2018-11-19 09:30:45 -08:00
Sean McArthur 7dabd34d24
Tower Retry (#96)
- Inspect the request, response, and error when determining to retry
- Return a future if retry is desired
  - This future allows an impl to delay a retry
  - The future yields a new `Policy`, allowing state to be changed
    for later retries.
2018-08-28 11:05:15 -07:00
Oliver Gould 5e0a2c7e2f Introduce tower-watch (#87)
`tower_watch::WatchService` provides a dynamically-bound `Service` that
updates in response to a `Watch`. A `WatchService` is constructed with a
`Watch<T>` and a `Bind<T>` -- `Bind` is a newly introduced trait that
supports instantiating new service instances with a borrowed value, i.e.
from a watch.

This can be used to reconfigure Services from a shared or otherwise
externally-controlled configuration source (for instance, a file
system).
2018-07-11 15:03:20 -07:00
Carl Lerche 295ae583d4
Remove `ReadyService` (#68)
The value added by having a separate trait is not obvious. Equivalent
behavior can be provided by a `Service` implementation that is always
"ready".
2018-04-25 14:32:13 -07:00
Carl Lerche 5369879af6
Extract `Service` trait and related into crate. (#67)
This makes the `tower` crate available to be a "batteries included"
facade.
2018-04-25 12:35:52 -07:00
Brian Smith e0ca6545bb Upgrade to env_logger 0.5 and log 0.4 so that projects that use those (#52)
versions don't have to build both those versions and the older ones
that h2 is currently using.

Don't enable the regex support in env_logger. Applications that want
the regex support can enable it themselves; this will happen
automatically when they add their env_logger dependency.

Disable the env_logger dependency in quickcheck.

The result of this is that there are fewer dependencies. For example,
regex and its dependencies are no longer required at all, as can be
seen by observing the changes to the Cargo.lock. That said,
env_logger 0.5 does add more dependencies itself; however it seems
applications are going to use env_logger 0.5 anyway so this is still
a net gain.

Submitted on behalf of Buoyant, Inc.

Signed-off-by: Brian Smith <brian@briansmith.org>
2018-02-23 20:24:22 -08:00
Carl Lerche 41c54b208e
InFlightLimit middleware (#49)
Provides a middleware that sets a maximum number of requests that can be
in-flight for the service. A request is defined to be in-flight from the
time `call` is invoked to the time the returned response future
resolves.

This maximum is enforced across all clones of the service instance.
2018-02-20 11:04:03 -08:00
Carl Lerche 942238237e
Move ReadyService to a dedicated crate. (#48)
This is the first step to resolve #44. The move will happen in two steps
to avoid breaking any libs depending on this now.
2018-02-19 11:53:29 -08:00
Carl Lerche bf2f704606 Remove reference to website 2017-11-16 11:26:36 -08:00
Carl Lerche ad6ff8c0d8 License Tower under MIT only
A dual MIT / Apache 2.0 license does not make any sense. Since the
intent of the original license was to be dual under MIT or Apache 2.0,
restricting to ony MIT is OK.
2017-11-16 09:44:44 -08:00
Carl Lerche 8d6daa45ea Prevent accidental publishing of the crates 2017-11-16 09:40:32 -08:00
Carl Lerche 9380a2c13a
Rename `tower-route` -> `tower-router`. (#26)
`Route` as a verb is easily confused with the noun.
2017-11-02 12:26:32 -07:00
Carl Lerche cd20feb484 Misc small fixes (#23) 2017-10-26 14:04:59 -07:00
Carl Lerche 4cb50eef77 Add tower-util (#19)
* NewServiceFn
* OptionService
* EitherService
2017-10-21 14:06:39 -07:00
Carl Lerche 87534a90de Initial buffer sketch (#13) 2017-10-10 10:38:40 -07:00
Carl Lerche 50905b330f Initial discovery, balance, and reconnect sketchs (#12) 2017-10-05 13:41:44 -07:00
Carl Lerche b45c7ee0d4 Add middleware 2017-10-03 10:03:14 -07:00
Carl Lerche bacb7dbfd2 Add backpresure capabilities to `Service` (#6)
Currently, `Service` does not provide a mechanism by which it can signal
to the caller that it is at capacity. This commit adds a `poll_ready`
function to the `Service` trait. Callers are able to first check
`poll_ready` before calling `Service::call`.

`poll_ready` is expected to be a hint and will be implemented in a best
effort fashion. It is permitted for a `Service` to return `Ready` from
`poll_ready` and the next invocation of `Service::call` fails.
2017-09-27 10:40:02 -07:00
Carl Lerche d5f253c577 Rename to Tower 2017-07-25 10:42:33 -07:00
Alex Crichton 6c5de5610f Update docs links and such 2017-01-11 09:20:40 -08:00
Alex Crichton 4d1c02566a Depend on futures from crates.io 2016-11-23 08:34:19 -08:00
Alex Crichton a3776005c3 Depend on futures from git 2016-11-08 18:59:00 -08:00
Kristoffer Søholm 636bf12fe8 Set futures version number to match the other repos 2016-09-09 20:09:19 -07:00
Alex Crichton 6faead4e63 Initial commit 2016-08-26 16:26:03 -07:00