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

Abierto
#9,132 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
docker-compose, postgresql, python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
9.9k
Forks
658
Merge medio
1 d 15 h
PR fusionados (30 d)
168

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Flagsmith/flagsmith

Todos los issues de Flagsmith/flagsmith

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.