Cold shape requests are slow when PostgreSQL has higher network latency
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- elixir, postgresql
- Domain
- databases, performance
Research direction
Start with the display_settings/0 implementation in the referenced Electric module and snapshot_query.ex, where the issue says Postgrex.query! runs each setting separately. Trace the snapshot transaction and compare cold request latency with the reproduction against a higher latency PostgreSQL connection. The suspected cause is unconfirmed; done means establishing whether combining the settings reduces sequential database calls and cold request latency.
Written by the indexing model from the issue text.
Description
I was testing Electric 1.8.1 and seeing a noticeable difference in cold shape request latency depending on how close Electric is to PostgreSQL. Database is hosted on Neon cloud.
- Local Electric → PostgreSQL (~60ms DB latency): request takes around 1.5 seconds
- Electric deployed closer to PostgreSQL (~20 ms DB latency): request takes around 300 ms
Warm requests return in a few milliseconds.
Reproduction
-
Run Electric against PostgreSQL with noticeable network latency.
-
Request a new shape with offset=-1 and a previously unused filter value:
curl -sS -G 'http://localhost:3000/v1/shape'
--data-urlencode 'table=public.example'
--data-urlencode 'offset=-1'
--data-urlencode 'where=run_id = $1'
--data-urlencode 'params[1]='
--output /dev/null
--write-out 'TTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' -
Repeat with different filter values to measure cold requests, then repeat the same requests to compare warm responses.
Suspected cause
The snapshot setup appears to make several sequential database calls, so network latency could account for a significant part of the delay.
Trace for a request that took 1.33s shows that span shape_snapshot.set_display_settings took 595ms, and shape_snapshot.query_fn took 414ms.
In particular, display_settings/0 in postgres.ex (https://github.com/electric-sql/electric/blob/%40core%2Fsync-service%401.8.1/packages/sync-service/lib/electric/postgres.ex) defines five statements:
SET bytea_output = 'hex';
SET DateStyle = 'ISO, DMY';
SET TimeZone = 'UTC';
SET extra_float_digits = 1;
SET IntervalStyle = 'iso_8601';
snapshot_query.ex (https://github.com/electric-sql/electric/blob/%40core%2Fsync-service%401.8.1/packages/sync-service/lib/electric/postgres/snapshot_query.ex) executes these through an Enum.map, calling Postgrex.query! separately for each statement inside the snapshot transaction.
Could these settings be applied in one database call, for example using a single SELECT with multiple set_config calls? I haven't tested that yet, so this is only suspected, not confirmed.
- Dominant language
- TypeScript
- Stars
- 10.4k
- Forks
- 394
- Avg merge
- 22h 11m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No 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 electric-sql/electric
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
electric-sql/electric#4830 ·
Maintainers usually reply within 1 day
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)Possibly taken @mohanedmoh claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
electric-sql/electric#4826 · 1 comment ·
Maintainers usually reply within 1 day
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wakePossibly taken @adityavkk claimed this 102 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
electric-sql/electric#4687 ·
Maintainers usually reply within 1 day
-
Listen IP addressOpenfeature request triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
electric-sql/electric#4150 · 1 comment ·
Maintainers usually reply within 1 day
-
ArrayDecoder doesn't handle escaped backslashes in quoted PostgreSQL array elementsPossibly taken @cpruijsen claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
electric-sql/electric#3708 ·
Maintainers usually reply within 1 day
All issues in electric-sql/electric
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
QuantumNous/new-api#7839 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
bug p2 triaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getpaseo/paseo#7071 · 1 comment ·
Maintainers usually reply within 1 day
-
test: make the #3408 Claude OAuth token fixture obviously fake so secret scanners stop flagging itOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
code-yeongyu/senpi#3436 ·
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 78/100
lingdojo/kana-dojo#32505 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day