Skip to content

Commit ad9c065

Browse files
authored
adjust
1 parent 31f12be commit ad9c065

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

frameworks/Python/blacksheep/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
READ_ROW_SQL = 'SELECT "id", "randomnumber" FROM "world" WHERE id = $1'
1717
WRITE_ROW_SQL = 'UPDATE "world" SET "randomnumber"=$1 WHERE id=$2'
1818
ADDITIONAL_ROW = [0, "Additional fortune added at request time."]
19-
MAX_CONNECTIONS = 1800
19+
MAX_CONNECTIONS = 2000
2020
CORE_COUNT = multiprocessing.cpu_count()
2121
WORKER_PROCESSES = CORE_COUNT
2222
MAX_POOL_SIZE = max(1, MAX_CONNECTIONS // WORKER_PROCESSES)

frameworks/Python/blacksheep/blacksheep-nginx-unit.dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ RUN pip3 install -r /blacksheep/requirements-uvicorn.txt -q
1111

1212
ENV PGSSLMODE=disable
1313
RUN CORE_COUNT=$(nproc) && \
14-
MAX_PROCESSES=$((CORE_COUNT)) && \
15-
sed -i "s|\"processes\": [0-9]*|\"processes\": $MAX_PROCESSES|g" /blacksheep/unit-config.json
16-
17-
RUN chmod +x start-unit.sh
14+
MAX_PROCESSES=$((CORE_COUNT <= 4 ? CORE_COUNT : CORE_COUNT)) && \
15+
SPARE_PROCESSES=$((MAX_PROCESSES // 4 > 0 ? MAX_PROCESSES // 4 : 1)) && \
16+
sed -i "s|\"max\": [0-9]*|\"max\": $MAX_PROCESSES|g" /blacksheep/unit-config.json && \
17+
sed -i "s|\"spare\": [0-9]*|\"spare\": $SPARE_PROCESSES|g" /blacksheep/unit-config.json && \
18+
sed -i "s|\"idle_timeout\": [0-9]*|\"idle_timeout\": 3600|g" /blacksheep/unit-config.json
1819

20+
# RUN chmod +x start-unit.sh
21+
RUN unitd && \
22+
curl -X PUT --data-binary @/blacksheep/unit-config.json --unix-socket \
23+
/var/run/control.unit.sock http://localhost/config
1924
ENTRYPOINT []
2025
EXPOSE 8080
21-
CMD ["./start-unit.sh"]
26+
CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock"]
27+
# CMD ["./start-unit.sh"]

frameworks/Python/blacksheep/blacksheep_conf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
import os
33

44
_is_travis = os.environ.get('TRAVIS') == 'true'
5+
CPU_CORES = multiprocessing.cpu_count()
6+
MAX_CONNECTIONS = 2000
7+
CONNECTIONS_PER_WORKER = 50
8+
max_pg_workers = MAX_CONNECTIONS // CONNECTIONS_PER_WORKER
59

6-
workers = multiprocessing.cpu_count()
10+
workers = min(CPU_CORES, max_pg_workers)
711
if _is_travis:
812
workers = 2
913

1014
bind = "0.0.0.0:8080"
11-
keepalive = 120
15+
keepalive = 1
16+
timeout = 0
1217
errorlog = '-'
1318
pidfile = '/tmp/blacksheep.pid'
1419
loglevel = 'error'

frameworks/Python/blacksheep/unit-config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"protocol": "asgi",
1313
"module": "app",
1414
"callable": "app",
15-
"processes": 56
15+
"processes": {
16+
"max": 56,
17+
"spare": 14,
18+
"idle_timeout": 3600
19+
}
1620
}
1721
},
1822
"access_log": "/dev/null"

0 commit comments

Comments
 (0)