Content-Length: 607977 | pFad | http://github.com/electric-sql/electric/commit/60160f3e82565cadc8d9f76415664a66e63eb750

4C feat: allow publication alter debounce to be configurable · electric-sql/electric@60160f3 · GitHub
Skip to content

Commit 60160f3

Browse files
committed
feat: allow publication alter debounce to be configurable
1 parent 543b204 commit 60160f3

File tree

8 files changed

+58
-15
lines changed

8 files changed

+58
-15
lines changed

.changeset/tidy-days-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@core/sync-service": patch
3+
---
4+
5+
feat: allow publication alter debounce to be configurable

packages/sync-service/config/runtime.exs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ config :electric,
202202
profile_where_clauses?: env!("ELECTRIC_PROFILE_WHERE_CLAUSES", :boolean, false),
203203
persistent_kv: persistent_kv_spec,
204204
listen_on_ipv6?: env!("ELECTRIC_LISTEN_ON_IPV6", :boolean, nil),
205-
secret: secret
205+
secret: secret,
206+
publication_alter_debounce_ms:
207+
env!(
208+
"ELECTRIC_PUBLICATION_ALTER_DEBOUNCE_TIME",
209+
&Electric.Config.parse_human_readable_time!/1,
210+
nil
211+
)
206212

207213
if Electric.telemetry_enabled?() do
208214
config :sentry,

packages/sync-service/lib/electric/application.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ defmodule Electric.Application do
128128
chunk_bytes_threshold: get_env(opts, :chunk_bytes_threshold),
129129
telemetry_opts:
130130
telemetry_opts([instance_id: instance_id, installation_id: installation_id] ++ opts),
131-
max_shapes: get_env(opts, :max_shapes)
131+
max_shapes: get_env(opts, :max_shapes),
132+
tweaks: [publication_alter_debounce_ms: get_env(opts, :publication_alter_debounce_ms)]
132133
)
133134
end
134135

packages/sync-service/lib/electric/config.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ defmodule Electric.Config do
6767
otel_per_process_metrics?: false,
6868
telemetry_top_process_count: 5,
6969
## Memory
70-
shape_hibernate_after: :timer.seconds(30)
70+
shape_hibernate_after: :timer.seconds(30),
71+
## Performance tweaks
72+
publication_alter_debounce_ms: 0
7173
]
7274

7375
@installation_id_key "electric_installation_id"

packages/sync-service/lib/electric/connection/supervisor.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ defmodule Electric.Connection.Supervisor do
7575
replication_opts = Keyword.fetch!(opts, :replication_opts)
7676
inspector = Keyword.fetch!(shape_cache_opts, :inspector)
7777
persistent_kv = Keyword.fetch!(opts, :persistent_kv)
78+
tweaks = Keyword.fetch!(opts, :tweaks)
7879

7980
shape_cache_spec = {Electric.ShapeCache, shape_cache_opts}
8081

8182
publication_manager_spec =
8283
{Electric.Replication.PublicationManager,
8384
stack_id: stack_id,
8485
publication_name: Keyword.fetch!(replication_opts, :publication_name),
85-
db_pool: Keyword.fetch!(db_pool_opts, :name)}
86+
db_pool: Keyword.fetch!(db_pool_opts, :name),
87+
update_debounce_timeout: Keyword.get(tweaks, :publication_alter_debounce_ms, 0)}
8688

8789
shape_log_collector_spec =
8890
{Electric.Replication.ShapeLogCollector,

packages/sync-service/lib/electric/replication/publication_manager.ex

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,14 @@ defmodule Electric.Replication.PublicationManager do
204204
else
205205
state = track_shape_handle(shape_handle, state)
206206
state = update_relation_filters_for_shape(shape, :add, state)
207-
state = add_waiter(from, state)
208-
state = schedule_update_publication(state.update_debounce_timeout, state)
209-
{:noreply, state}
207+
208+
if update_needed?(state) do
209+
state = add_waiter(from, state)
210+
state = schedule_update_publication(state.update_debounce_timeout, state)
211+
{:noreply, state}
212+
else
213+
{:reply, :ok, state}
214+
end
210215
end
211216
end
212217

@@ -217,16 +222,25 @@ defmodule Electric.Replication.PublicationManager do
217222
else
218223
state = untrack_shape_handle(shape_handle, state)
219224
state = update_relation_filters_for_shape(shape, :remove, state)
220-
state = add_waiter(from, state)
221-
state = schedule_update_publication(state.update_debounce_timeout, state)
222-
{:noreply, state}
225+
226+
if update_needed?(state) do
227+
state = add_waiter(from, state)
228+
state = schedule_update_publication(state.update_debounce_timeout, state)
229+
{:noreply, state}
230+
else
231+
{:reply, :ok, state}
232+
end
223233
end
224234
end
225235

226236
def handle_call({:refresh_publication, forced?}, from, state) do
227-
state = add_waiter(from, state)
228-
state = schedule_update_publication(state.update_debounce_timeout, forced?, state)
229-
{:noreply, state}
237+
if forced? or update_needed?(state) do
238+
state = add_waiter(from, state)
239+
state = schedule_update_publication(state.update_debounce_timeout, forced?, state)
240+
{:noreply, state}
241+
else
242+
{:reply, :ok, state}
243+
end
230244
end
231245

232246
def handle_call({:recover_shape, shape_handle, shape}, _from, state) do
@@ -307,6 +321,18 @@ defmodule Electric.Replication.PublicationManager do
307321
),
308322
do: %{state | next_update_forced?: forced? or state.next_update_forced?}
309323

324+
defp update_needed?(%__MODULE__{
325+
prepared_relation_filters: commited,
326+
committed_relation_filters: prepared,
327+
row_filtering_enabled: row_filtering_enabled
328+
}) do
329+
cond do
330+
prepared == commited -> false
331+
not row_filtering_enabled and Map.keys(prepared) == Map.keys(commited) -> false
332+
true -> true
333+
end
334+
end
335+
310336
# Updates are forced when we're doing periodic checks: we expect no changes to the filters,
311337
# but we'll write them anyway because that'll verify that no tables have been dropped/renamed
312338
# since the last update. Useful when we're not altering the publication often to catch changes

packages/sync-service/lib/electric/replication/supervisor.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ defmodule Electric.Replication.Supervisor do
3939
consumer_supervisor,
4040
publication_manager,
4141
log_collector,
42-
schema_reconciler,
43-
shape_cache
42+
shape_cache,
43+
schema_reconciler
4444
]
4545

4646
Supervisor.init(children, strategy: :one_for_all)

packages/sync-service/lib/electric/stack_supervisor.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ defmodule Electric.StackSupervisor do
9696
"tweaks to the behaviour of parts of the supervision tree, used mostly for tests",
9797
default: [],
9898
keys: [
99+
publication_alter_debounce_ms: [type: :non_neg_integer, default: 0],
99100
registry_partitions: [type: :non_neg_integer, required: false],
100101
monitor_opts: [
101102
type: :keyword_list,

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/electric-sql/electric/commit/60160f3e82565cadc8d9f76415664a66e63eb750

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy