File: flask.md

package info (click to toggle)
hishel 0.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,548 kB
  • sloc: python: 6,387; sh: 13; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
icon: simple/flask
---

As a `Flask` user, you can use the power of `HTTPX` using its synchronous interface.

Here is a simple example:

``` python
from flask import Flask
from httpx import Client
from httpx import Limits

app = Flask(__name__)
client = Client(limits=Limits(max_connections=1000))

@app.route("/")
def main():
    response = client.get('https://www.encode.io')
    return str(response.status_code)
```

Now let's do some load testing using the popular load testing tool [Locust](https://locust.io/).

[Here are](https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/flask_without_cache.png) the test results:

<a href="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/flask_without_cache.png">
    <img src="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/flask_without_cache.png" alt="pypi">
</a>

We got only **±20 RPS**, which is not very good.

Now let's change the `httpx.Client` to `hishel.CacheClient` and do the same tests again.

``` python hl_lines="2 6"
from flask import Flask
from hishel import CacheClient
from httpx import Limits

app = Flask(__name__)
client = CacheClient(limits=Limits(max_connections=1000))

@app.route("/")
def main():
    response = client.get('https://www.encode.io')
    return str(response.status_code)
```

[Here are](https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/flask_with_cache.png) the test results:

<a href="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/flask_with_cache.png">
    <img src="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/flask_with_cache.png" alt="pypi">
</a>

Now we have more than **±800 RPS** using the power of HTTP caching.