Skip to content

Commit 881c8e6

Browse files
committed
typos, clientbot results links
1 parent 3492a93 commit 881c8e6

File tree

2 files changed

+87
-39
lines changed

2 files changed

+87
-39
lines changed

README.md

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# ApiGuard
22

3+
- [Overview](#overview)
4+
- [Features](#features)
5+
- [How it works](#how-it-works)
6+
- [Getting Started](#getting-started)
7+
- [Prerequisites](#prerequisites)
8+
- [Installation](#installation)
9+
- [Configuration](#configuration)
10+
- [Building and Running via Zig](#building-and-running-the-service-via-zig)
11+
- [Running the Service in Production](#running-the-service-in-production)
12+
- [Running the Service via Docker
13+
Container](#running-the-service-via-docker-container)
14+
- [Furhat Kotlin Client Example](#furhat-kotlin-client-example)
15+
- [ApiGuard API](#apiguard-api)
16+
- [Endpoints](#endpoints)
17+
- [Example Responses](#example-responses)
18+
319
## Overview
420

521
ApiGuard is a rate limiting service designed to manage and protect API endpoints
@@ -42,7 +58,7 @@ incoming requests to consecutive time-slots.
4258
For n=500, the time-slots are 120ms apart. So the first request will have a
4359
delay of 0ms since it is the first one. The second request will be put on the
4460
second time-slot 120ms apart from the first -> delay=120ms, if both requests
45-
arrived at the same time.
61+
arrive at the same time.
4662

4763
If the second request comes in 50ms after the first, then the allocated
4864
time-slot for it will still be the second time-slot 120ms apart from the first
@@ -56,7 +72,7 @@ request of another client than the one that sent the first three, that other
5672
client's first request will be delayed by 360ms, according to its assigned
5773
time-slot.
5874

59-
Time-slots that aren't used because of slow clients, will be put into a list of
75+
Time-slots that aren't used because of slow clients will be put into a list of
6076
"free passes" that encounter **no delay**. This allows for quickly catching up
6177
and lowering the API request delay when the API hasn't been used for a few
6278
time-slots.
@@ -71,7 +87,7 @@ old 498 free passes must not be used to guarantee time-slotting to work.
7187
All the constraints mentioned above have been tested under load. See
7288
[clientbot](clientbot.md) for more information.
7389

74-
The following example illustrates many of the things mentioned above: 5
90+
The following example illustrates many of the things mentioned above: 3
7591
concurrent clients that sleep for 5s every 50 requests, allowing the server to
7692
use some of the free passes after those delays, etc. While for each individual
7793
client the mean delay is > 120ms, API-requests for all clients combined are
@@ -188,10 +204,10 @@ curl http://127.0.0.1:${APIGUARD_PORT}${APIGUARD_SLUG}/request_access
188204
2. Load the image into docker:
189205
```bash
190206
docker load < downloaded_file
191-
# or, if you build it with nix:
207+
# or, if you built it with nix:
192208
docker load < result
193209
```
194-
3. Create an api_guard.rc file, see [configuration](#configuration) and set its PORT to
210+
3. Create an api_guard.rc file, see [configuration](#configuration), and set its PORT to
195211
5500. That port is just used inside the container:
196212
```
197213
PORT=5500
@@ -214,7 +230,37 @@ curl http://127.0.0.1:${APIGUARD_PORT}${APIGUARD_SLUG}/request_access
214230
# run a simple request
215231
curl http://127.0.0.1:${APIGUARD_PORT}${APIGUARD_SLUG}/request_access
216232
```
217-
## Usage
233+
### Furhat Kotlin Client Example
234+
235+
Here comes a code snippet you can use in a Furhat robot skill which is what this
236+
service has initially been developed for:
237+
238+
1. Add the `khttp` dependency to your `build.gradle`:
239+
```gradle
240+
dependencies {
241+
implementation 'com.furhatrobotics.furhatos:furhat-commons:2.7.1'
242+
implementation 'com.theokanning.openai-gpt3-java:service:0.16.0'
243+
compile 'khttp:khttp:1.0.0'
244+
}
245+
```
246+
247+
2. Before making a request to your API, insert the following lines:
248+
```kotlin
249+
// make a khttp request to api guard
250+
val API_GUARD_URL = "https://your.domain.org/api_guard"
251+
val API_GUARD_KEY = "YOUR AUTH TOKEN"
252+
val guard_response = khttp.get(
253+
"$API_GUARD_URL/request_access?handle_delay=true",
254+
headers=mapOf("Authorization" to "Bearer " + API_GUARD_KEY)
255+
).text
256+
print("API Guard said: $guard_response")
257+
```
258+
259+
This will let the server take care of rate limiting your API calls.
260+
261+
**Note:** Make sure to prepend 'Bearer ' to your API token as shown above!
262+
263+
## ApiGuard API
218264
219265
### Endpoints
220266
@@ -254,36 +300,6 @@ curl http://127.0.0.1:${APIGUARD_PORT}${APIGUARD_SLUG}/request_access
254300
- **Example**:
255301
- [`AUTH_TOKEN=YOUR_TOKEN ./test_set_params.sh`](./test_set_params.sh): how to set values via `/set_rate_limit`
256302
257-
### Furhat Kotlin Example
258-
259-
Here comes a code snippet you can use in a Furhat robot skill which is what this
260-
service has initially been developed for:
261-
262-
1. Add the `khttp` dependency to your `build.gradle`:
263-
```gradle
264-
dependencies {
265-
implementation 'com.furhatrobotics.furhatos:furhat-commons:2.7.1'
266-
implementation 'com.theokanning.openai-gpt3-java:service:0.16.0'
267-
compile 'khttp:khttp:1.0.0'
268-
}
269-
```
270-
271-
2. Before making a request to your API, insert the following lines:
272-
```kotlin
273-
// make a khttp request to api guard
274-
val API_GUARD_URL = "https://your.domain.org/api_guard"
275-
val API_GUARD_KEY = "YOUR AUTH TOKEN"
276-
val guard_response = khttp.get(
277-
"$API_GUARD_URL/request_access?handle_delay=true",
278-
headers=mapOf("Authorization" to "Bearer " + API_GUARD_KEY)
279-
).text
280-
print("API Guard said: $guard_response")
281-
```
282-
283-
This will let the server take care of rate limiting your API calls.
284-
285-
**Note:** Make sure to prepend 'Bearer ' to your API token as shown above!
286-
287303
### Example Responses
288304
289305
Please see the examples:

clientbot.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
The clientbot allows for flexible testing of the server.
44

5-
### Building it
5+
## Building it
66

77
The bot gets built along with the server when you run `zig build`.
88

9-
### Running it
9+
## Running it
1010

1111
You run it from the commandline:
1212

@@ -21,7 +21,7 @@ Usage: clientbot num-threads requests-per-thread handle_delay outfile [n (reques
2121
sleep_ms : OPTIONAL: if n: how long the client should sleep
2222
```
2323

24-
### Pre-Configured runs
24+
## Pre-Configured runs
2525

2626
Check out the [load_tests](./load_tests/) folder for scripts and its
2727
[results](./load_tests/results/) folder for the generated results. It contains
@@ -51,3 +51,35 @@ kill $pid
5151
python ../plot_timeline.py $OUTFILE
5252

5353
```
54+
55+
### 1 Client x 1000 requests
56+
57+
[results](./load_tests/results/l001_c1_r1000.json.html)
58+
59+
### 2 Clients x 500 requests each
60+
61+
[results](./load_tests/results/l002_c2_r500.json.html)
62+
63+
### 5 Clients x 500 requests each
64+
65+
[results](./load_tests/results/l003_c5_r500.json.html)
66+
67+
### 10 Clients x 500 requests each
68+
69+
[results](./load_tests/results/l004_c10_r500.json.html)
70+
71+
### 2 Clients x 500 requests each, sleeping for 5s every 50 requests
72+
73+
[results](./load_tests/results/l005_c2_r500s50d5000.json.html)
74+
75+
### 3 Clients x 500 requests each, sleeping for 5s every 50 requests
76+
77+
[results](./load_tests/results/l006_c3_r500s50d5000.json.html)
78+
79+
### 1 Client x 1000 requests, sleeping for 5s every 50 requests
80+
81+
[results](./load_tests/results/l007_c1_r1000s50d5000.json.html)
82+
83+
### 5 clients x 500 requests each, sleeping for 5s every 100 requests
84+
85+
[results](./load_tests/results/l008_c5_r500s100d5000.json.html)

0 commit comments

Comments
 (0)