Self-hosted: Postgres JIT makes the environment lookup take ~3 s, so SDK events time out
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 9.9k
- Forks
- 658
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 168
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Flagsmith/flagsmith
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Flagsmith/flagsmith#9119 · 1 comment ·
Maintainers usually reply within 1 day
-
Fix Button Alignment in SDK Installation SectionPossibly taken @manueldezman claimed this 3 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Flagsmith/flagsmith#9056 · 2 comments ·
Maintainers usually reply within 1 day
-
Cloud Python warehouse snippet omits the import needed by its short-lived-job guidancePossibly taken @jcd1991 claimed this 4 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Flagsmith/flagsmith#9045 · 1 comment ·
Maintainers usually reply within 1 day
-
Expose whether an organisation is blocked for API usagePossibly taken @PiUnknown claimed this 38 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Flagsmith/flagsmith#8773 · 1 comment ·
Maintainers usually reply within 1 day
-
influx_query_manager doesn't catch ApiException, so Influx error responses 500Possibly taken @SAY-5 claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Flagsmith/flagsmith#8510 · 1 comment ·
Maintainers usually reply within 1 day
All issues in Flagsmith/flagsmith
Similar issues
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
Maintainers usually reply within 1 day
-
CI: MSYS2 jobs fail — mingw python3 package renamed upstream to pythonPossibly taken @ronaldtse claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
pydantic/pytest-examples#102 · 1 comment ·