From 212adb1e25c4f472d97f25df7b6681f41ed453a8 Mon Sep 17 00:00:00 2001 From: RRRosmontis Date: Sun, 13 Sep 2026 02:26:34 +0800 Subject: [PATCH] =?UTF-8?q?perf(pixiv):=20=E6=94=B9=E7=94=A8=20waitress=20?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0=EF=BC=8C=E7=BC=93=E5=AD=98=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=94=B9=E4=B8=BA=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - IMAGE_DIR 由硬编码 /home/pixiv/images 改为 (Path(__file__).parent/'../cache/pixiv/images').resolve() (即 source/cache/pixiv/images),mkdir 补 parents=True - systemd/pixiv.service: ExecStart 改为 waitress-serve --host=127.0.0.1 --port=9007 --threads=8 pixiv:app 替代 Flask 开发服务器(thread-per-request 无上限,突发流量下线程爆炸) - __main__ 兜底加 threaded=True,手动运行时不串行 --- source/pixiv/pixiv.py | 6 +++--- systemd/pixiv.service | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/pixiv/pixiv.py b/source/pixiv/pixiv.py index f0f572b..eecca02 100644 --- a/source/pixiv/pixiv.py +++ b/source/pixiv/pixiv.py @@ -12,8 +12,8 @@ USER_AGENT = "PixivIOSApp/7.13.0 (iOS 14.6; iPhone)" urllib3.disable_warnings() -IMAGE_DIR = Path("/home/pixiv/images") -IMAGE_DIR.mkdir(exist_ok=True) +IMAGE_DIR = (Path(__file__).resolve().parent / "../cache/pixiv/images").resolve() +IMAGE_DIR.mkdir(parents=True, exist_ok=True) app = Flask(__name__) @@ -196,4 +196,4 @@ if __name__ == '__main__': else: print("Warning: access_token missing in tokens.json") print(f"Cache directory: {IMAGE_DIR}") - app.run(host='0.0.0.0', port=9088, debug=False) \ No newline at end of file + app.run(host='127.0.0.1', port=9007, debug=False, threaded=True) \ No newline at end of file diff --git a/systemd/pixiv.service b/systemd/pixiv.service index ca19eac..0f64967 100644 --- a/systemd/pixiv.service +++ b/systemd/pixiv.service @@ -8,7 +8,7 @@ Type=simple User=root WorkingDirectory=/home/openapi/source/pixiv Environment=PATH=/home/openapi/env/general/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ExecStart=/home/openapi/env/general/bin/python /home/openapi/source/pixiv/pixiv.py +ExecStart=/home/openapi/env/general/bin/waitress-serve --host=127.0.0.1 --port=9007 --threads=8 pixiv:app Restart=always RestartSec=5 StandardOutput=append:/var/log/pixiv.log