You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Critical Issue: CDC Sequin v0.6.41 Pod Continuously Crashing Due to OOM (Out of Memory) #881
Description:
We are encountering a critical issue with CDC Sequin version 0.6.41 where the pod is continuously crashing due to Out of Memory (OOM) errors. This issue began after upgrading from version 0.6.39 to 0.6.41. Despite increasing the memory allocation from 500M to 2G, the problem persists, and the pod crashes after approximately 2 days of runtime. Restarting the pod does not resolve the issue, and the OOM errors recur.
We suspect there may be a memory leak or a bug in the application, as the volume of messages being processed does not justify the memory usage.
Steps to Reproduce:
Deploy CDC Sequin service version 0.6.41.
Start the service and let it run for several days.
Observe the pod behavior and monitor memory usage.
Check the logs for OOM errors and pod crashes.
Additional Context:
Memory allocation increased from 500M to 2G without resolving the issue.
Pod crashes and OOM errors persist even after restarts.
Logs indicate no significant increase in message volume to justify memory exhaustion.
Expected Behavior:
The pod should run stably without OOM errors, even after prolonged operation.
Actual Behavior:
The pod crashes due to OOM errors after approximately 2 days of runtime, regardless of restarts or increased memory allocation.
Request:
Please investigate this issue for potential memory leaks or bugs in CDC Sequin v0.6.41. Let us know if additional logs or details are required to assist with debugging.
2025-01-17T02:25:30.184061609Z stdout F [warning] [02:25:30.183] Received 20 messages for consumer 2825d476-6216-4e28-9b11-2b22611bfad9 that have already been delivered line=157 pid=<0.4224.0> file=lib/sequin/consumers_runtime/consumer_producer.ex domain=elixir application=sequin
@dengziwu-ctw We'll ship a change tomorrow that will let you set a maximum memory size per replication slot (and downstream processes). When we hit the max mem size, we'll apply back pressure as needed until messages are flushed to Kafka.
We suspect increasing the concurrency to Kafka (as we passed along to your colleague) will help a lot. Can you try that and see if it helps?
We also added logging in v0.6.45 that will help us get to the bottom of this
We can use the WAL on the postgres instance as the buffer. Before vendoring additional code we have some tools at our disposal:
We can start the SlotProcessor, inducing Postgres to send us all WAL messages since our last confirmed_flush_lsn
We can stop the SlotProcessor, preventing Postgres from sending us any more messages
With just this we can build an in-memory buffer with a constraint on max memory usage. And guarantee at-least-once delivery of messages from WAL to SMSs.
The SlotProcessor can pass messages to the SMSs until a memory high water mark is reached at which point it shuts down.
Some process that is still alive needs to perform two periodic functions:
Monitor memory usage. When memory usage drops low enough we will restart the SlotProcessor
Monitor min_unflushed_lsn of SlotMessageStores and potentically increment/persist last_processed_seq.
When we reboot we discard messages until seq > last_processed_seq (protecting our memory usage) , then begin calling messages to SMSs, and monitoring memory usage.
If we hit a commit and SMSs flush it, we confirm_flush_lsn to postgres and we are done with this condition.
If we have to enter this loop several times to chew through a xxl transaction, that is okay. There is unnecessary network and cpu usage as we chew through gigabytes of messages from the WAL but that is fine for now.
When can this happen? Does this solution address those conditions?
*This can occur for healthy consumers when Postgres sends us messages faster than the downstream processes can ack them. ie. after a very large transaction or if a data migration kicks increase postgres operations per second
This can occur for an unhealthy consumer that can no longer deliver messages. Eventually we will accrue many messages in memory
SlotMessageStore memory optimization fits well
Interestingly, because we are monitoring memory explicitly, we can separately modify SMSs behavior to utilize less memory in these scenarios.
For instance we discussed flushing messages to disk but only retaining in SMS memory the ones that are deliverable. If we implement some strategy to reduce SMS memory usage, we automatically avoid entering Replication shut down condition
This helps to decouple one failing ConsumerPipeline from shutting down the SlotProcessor for other healthy ConsumerPipelines
Might be good to have a configurable maximum byte count that Sequin downloads from the WAL to internal buffers in order to control memory usage. Large transactions leading to possible OOMKill is a bit unworkable. Also, would be nice to have guidelines in the documentation as to how much memory a sequin instance could need in relation to the size of the buffers so we can set safe mem limits to containers.
Activity
dengziwu-ctw commentedon Jan 17, 2025
dengziwu-ctw commentedon Jan 17, 2025
2025-01-17T02:25:30.184061609Z stdout F [warning] [02:25:30.183] Received 20 messages for consumer 2825d476-6216-4e28-9b11-2b22611bfad9 that have already been delivered line=157 pid=<0.4224.0> file=lib/sequin/consumers_runtime/consumer_producer.ex domain=elixir application=sequin
when oom, there is so many warning like this
acco commentedon Jan 17, 2025
Thanks @dengziwu-ctw , chatting with your colleague in Discord now
acco commentedon Jan 17, 2025
@dengziwu-ctw We'll ship a change tomorrow that will let you set a maximum memory size per replication slot (and downstream processes). When we hit the max mem size, we'll apply back pressure as needed until messages are flushed to Kafka.
We suspect increasing the concurrency to Kafka (as we passed along to your colleague) will help a lot. Can you try that and see if it helps?
We also added logging in
v0.6.45that will help us get to the bottom of thisdengziwu-ctw commentedon Jan 17, 2025
update sequin_config.sink_consumers
set max_waiting = 100
where type = 'kafka';
after set this, the problem seems fixed, I will keep an eye on it in future days
RTLS commentedon Jan 18, 2025
We can use the WAL on the postgres instance as the buffer. Before vendoring additional code we have some tools at our disposal:
confirmed_flush_lsnWith just this we can build an in-memory buffer with a constraint on max memory usage. And guarantee at-least-once delivery of messages from WAL to SMSs.
The SlotProcessor can pass messages to the SMSs until a memory high water mark is reached at which point it shuts down.
Some process that is still alive needs to perform two periodic functions:
min_unflushed_lsnof SlotMessageStores and potentically increment/persistlast_processed_seq.When we reboot we discard messages until
seq > last_processed_seq(protecting our memory usage) , then begin calling messages to SMSs, and monitoring memory usage.If we hit a commit and SMSs flush it, we
confirm_flush_lsnto postgres and we are done with this condition.If we have to enter this loop several times to chew through a xxl transaction, that is okay. There is unnecessary network and cpu usage as we chew through gigabytes of messages from the WAL but that is fine for now.
When can this happen? Does this solution address those conditions?
*This can occur for healthy consumers when Postgres sends us messages faster than the downstream processes can ack them. ie. after a very large transaction or if a data migration kicks increase postgres operations per second
SlotMessageStore memory optimization fits well
Interestingly, because we are monitoring memory explicitly, we can separately modify SMSs behavior to utilize less memory in these scenarios.
For instance we discussed flushing messages to disk but only retaining in SMS memory the ones that are deliverable. If we implement some strategy to reduce SMS memory usage, we automatically avoid entering Replication shut down condition
This helps to decouple one failing ConsumerPipeline from shutting down the SlotProcessor for other healthy ConsumerPipelines
ronkkol commentedon Jan 28, 2025
Might be good to have a configurable maximum byte count that Sequin downloads from the WAL to internal buffers in order to control memory usage. Large transactions leading to possible OOMKill is a bit unworkable. Also, would be nice to have guidelines in the documentation as to how much memory a sequin instance could need in relation to the size of the buffers so we can set safe mem limits to containers.
acco commentedon Jan 28, 2025
Hey @ronkkol -- we're working on configurable controls for memory consumption now!
acco commentedon Jan 31, 2025
We've deployed more memory controls. You can find them documented here:
https://sequinstream.com/docs/reference/configuration#runtime-configuration
Still more we want to do - but closing this ticket for now. Please let us know if you see any other issues here 🙏