Skip to content

Commit

Permalink
Add README to collapsed forwarding code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredririe committed Oct 11, 2018
1 parent d56a827 commit 8c98b7b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions code/collapsed-forwarding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Collapsed Forwarding Example: Request Batcher

This is an example of collapsed forwarding which batches together requests for the same URL. Every five seconds, a `requestBatcher` flushes its batches of requests by handling one request from each batch and giving the same result to the rest of the requests in that batch.

This code was written for the sole purpose of explaining the concept of collapsed forwarding. It is not intended for production use and has known inefficiencies and flaws.

## Getting it running

```bash
$ go build && ./collapsed-forwarding
[server] running on port :8081
[proxy] running on port :8080
```

Once the proxy and server are running, make a request to `localhost:8080/<URL>`. The response should be the provided <URL>:

```bash
$ curl localhost:8080/test
/test
```

Make several requests to the proxy in the background.

```bash
$ curl localhost:8080/test &
$ curl localhost:8080/test &
$ curl localhost:8080/test &
$ curl localhost:8080/test &
```

The application should log each request, find four batched requests, and then make a single request to the server:

```
[proxy] /test
[proxy] /test
[proxy] /test
[proxy] /test
4 batched requests under key "/test"
[server] /test
```

0 comments on commit 8c98b7b

Please sign in to comment.