You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-2Lines changed: 33 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,7 +162,7 @@ Options:
162
162
human-readable duration) an idle blocking
163
163
thread will be kept alive [env var:
164
164
GRANIAN_BLOCKING_THREADS_IDLE_TIMEOUT;
165
-
default: 30; 10<=x<=600]
165
+
default: 30; 5<=x<=600]
166
166
--runtime-threads INTEGER RANGE
167
167
Number of runtime threads (per worker) [env
168
168
var: GRANIAN_RUNTIME_THREADS; default: 1;
@@ -460,9 +460,11 @@ Given you specify N threads with the relevant option, in **st** mode Granian wil
460
460
461
461
Benchmarks suggests **st** mode to be more efficient with a small amount of processes, while **mt** mode seems to scale more efficiently where you have a large number of CPUs. Real performance will though depend on specific application code, and thus *your mileage might vary*.
462
462
463
+
By default (**auto** mode), Granian will pick the best option based on the rest of its configuration.
464
+
463
465
### Metrics
464
466
465
-
Granian exposes the following runtime metrics in Prometheus format. All the metrics are prefixed with `granian_`, and ones marked with *worker* scope are tagged with a `worker` label containing the worker ID.
467
+
Granian exposes the following runtime metrics in Prometheus format. All the metrics are prefixed with `granian_`, and the ones marked with *worker* scope are tagged with a `worker` label containing the worker ID.
466
468
467
469
| metric name | type | unit | scope | description |
468
470
| --- | --- | --- | --- | --- |
@@ -484,6 +486,35 @@ Granian exposes the following runtime metrics in Prometheus format. All the metr
484
486
|`blocking_busy_cumulative`| counter | microseconds | worker | Cumulative busy time spent in the blocking threadpool |
485
487
|`py_wait_cumulative`| counter | microseconds | worker | Cumulative time spent waiting on GIL (on the free-threaded build this is always 0) |
486
488
489
+
### Static files
490
+
491
+
Granian offers the ability to *offload* static files serving directly to the server, without calling your Python application in the process.
492
+
493
+
The `--static-path-route` and `--static-path-mount` options accept multiple values, thus you can serve an arbitrary number of static *locations* in your application, the only condition being the number of routes and mounts specified should be the same:
494
+
495
+
```
496
+
$ granian \
497
+
--static-path-route /static \
498
+
--static-path-mount assets/static \
499
+
--static-path-route /media \
500
+
--static-path-mount assets/media \
501
+
package:app
502
+
```
503
+
504
+
#### Serving a specific file for directory listings
505
+
506
+
Granian also provides the option to *rewrite* a static location pointing to a directory to a file contained in such directory. This allows you to serve, for example, an `index.html` file in the static path tree:
507
+
508
+
```
509
+
$ granian \
510
+
--static-path-route /docs \
511
+
--static-path-mount generated/docs \
512
+
--static-path-dir-to-file index.html \
513
+
package:app
514
+
```
515
+
516
+
> **Note:** while Granian performs a rewrite on the target directory, the file will still be served if the request path points to it directly (in the example above, requests pointing to `/docs/somefolder` and `/docs/somefolder/index.html` will both respond with the contents of `index.html` – if present). Also, the option will enable this behavior on all the static paths defined.
517
+
487
518
### Proxies and forwarded headers
488
519
489
520
Since none of the supported applications protocols define a strategy for proxies' *forwarded headers*, Granian doesn't provide any option to configure its behaviour around them.
0 commit comments