Self-hosted: Postgres JIT makes the environment lookup take ~3 s, so SDK events time out

未关闭
#9,132 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
docker-compose, postgresql, python
领域
backend, databases

调研方向

Start by finding the environment-by-key lookup that combines the Environment and EnvironmentAPIKey queries, then inspect the self-hosting Docker Compose configuration. Compare the reported query with JIT enabled and disabled to confirm the cause. Done means avoiding the reported multi-second lookup for self-hosted PostgreSQL users without changing lookup behavior.

由索引模型根据 Issue 内容生成。

描述

Setup: the docker-compose from the self-hosting docs, Flagsmith 2.295.2, postgres:15.5-alpine (JIT on, the Postgres default), Experimentation enabled.

What happens: about one SDK request in five took just over 3 seconds (/api/v1/flags/, /api/v1/events; /health/liveness/ was always fast). With log_min_duration_statement on, the slow statement is the environment-by-key lookup: the UNION of the Environment and EnvironmentAPIKey queries with ~100 selected columns. pg_stat_activity shows it active with no wait event, i.e. CPU. EXPLAIN ANALYZE of the logged statement:

jit Execution
on (default) 2,840 ms
off 2.4 ms

It runs on every per-process cache miss, so more gunicorn workers make it more frequent.

Why it matters: the Python SDK's event sender uses a 3-second read timeout. Exposures sent during a slow lookup were retried and stored twice, or dropped (Failed to send 1 events, attempt 1 of 3: Read timed out. (read timeout=3)). On an experiment wired correctly, 3 of 20 conversions disappeared, which looks exactly like a wiring bug.

Fix that worked for us:

  postgres:
    image: postgres:15.5-alpine
    command: ["postgres", "-c", "jit=off"]

After it: 0 of 120 requests over 1 s, max 0.22 s. Turning JIT off in the official compose file (or making that lookup a UNION ALL) would avoid it for everyone self-hosting.

主要语言
Python
星标
9.9k
派生
658
平均合并
1 天 15 小时
30 天内合并 PR
168

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Flagsmith/flagsmith 的其他 Issue

查看 Flagsmith/flagsmith 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。