loggregator icon indicating copy to clipboard operation
loggregator copied to clipboard

log-api under load fills up memory and start swapping

Open michaelgrifalconi opened this issue 8 years ago • 13 comments

We have a test system with 1000 deployed applications. Each application is bound to its own syslog drain service.

Starting with 2 log-api VMs (2 cpu, 4gb ram) we gradually increased the number of logs sent by the test applications. To handle more load, we scaled the adapters up to 12 instances before starting to experience issue on log-api VMs.

Approaching the maximum load of log-api we saw an increase of memory usage up to 100% and the VM started to swap.

The expected behaviour would be to handle the load by dropping logs before starting to swap.

Doppler are 2 VMs 2cpu, 4gb ram each.

This was tested on loggregator-release v99 (the one used for etcd-removal migration) and the 101.4 (the one in cf-deployment 1.9.0)

michaelgrifalconi avatar Feb 05 '18 12:02 michaelgrifalconi

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/154920005

The labels on this github issue will be updated when the story is started.

cf-gitbot avatar Feb 05 '18 12:02 cf-gitbot

@tyyko I suspect the ReverseLogProxy (which is what the adapters read from on the log-api) are handling too many connections. Given your numbers (and an estimate of 256 bytes per envelope) I come up with the following:

  • 2000 connections (Adapters make 2 connections per drain)
  • 10000 envelopes buffered per connection (channel size is 10000)
  • 256 bytes per envelope
2000 * 10000 * 256 => 5120000000B
5120000000B/1024.0/1024.0/1024.0 => 4.768GB

So that spread out across 2 RLPs does not leave much room for the rest of the process (or any other process) to allocate memory.

The RLP has a max connection count of 2000, but perhaps that is too much for your VM specs.

poy avatar Feb 06 '18 13:02 poy

This means that this problem should go away when I double the memory size of the VM, right? I'll do in our test bed right now...

holgero avatar Feb 06 '18 16:02 holgero

You can either scale vertically (bump up VM size) or horizontally (add more instances of log-api).

poy avatar Feb 06 '18 17:02 poy

When I scale horizontally the VM can always go into swapping, because the connection limit is 2000 connections, or am I mistaken?

holgero avatar Feb 06 '18 17:02 holgero

If you scale up, the 2000 should get spread across more VMs.

poy avatar Feb 06 '18 17:02 poy

That will only help until the number of applications increases and it causes the rlp to crash again. This means that there is a minimum memory requirement for the rlp and that one cannot run it on a VM with less memory. And you calculated that minimum memory requirement above to be at least 5 GiB.

holgero avatar Feb 08 '18 09:02 holgero

Agreed. The Loggregator system has the expectation that proper capacity planning has been considered.

poy avatar Feb 08 '18 13:02 poy

My expectation is that improper capacity planning leads to dropped messages, not the stack crashing. Also proper capacity planning requires proper documentation.

holgero avatar Feb 08 '18 14:02 holgero

@holgero we performed capacity tests and documented these results in the Operator Guidebook which is available on our README.md. In the test we use a c3.large vm types on GCP and didn't encounter any memory pressure. We have pipelines available if you'd like to repeat the tests with different vertical scaling.

Granted we started with large vm sizes and stressed them from a CPU and network perspective. We are going to put in logic here and for adapters and RLPs to refuse connections (in turn dropping messages) rather than swap as you are experience. We have encountered several operators under sizing or sharing critical resources recently and can probably make our recommendations easy to find.

hev avatar Feb 08 '18 17:02 hev

@ahevenor Thank you for the pointer to the guidebook. The capacity tests described there seem to focus a bit on the doppler and on the comparison between UDP and gRPC. Also they test only the capacity of the syslog stream capability via traffic-controller and nozzles, not the syslog drain (via reverse log proxy and adapter). The section about syslog drain reliability measurement seems to be theoretical, or at least I didn't find the results of that part. Or am I missing something completely here?

holgero avatar Feb 13 '18 15:02 holgero

@holgero Apologies for the slow response and lack of detail in the report. I had to dig out my notebooks to better recall what testing I had done. To your point, we did not publish these results. At the time the cf-syslog-drain release was not yet GA, because cf-deployment was not yet GA so I decided not to include the results which focused on reliability mostly not scaling of the adapter. I did not stress adapters beyond 500 drains per adapter which would have (eventually) lead to us seeing the swapping behavior.

We have since implemented a max_drain_bindings limit with a default of 500 so that you can prevent adapters from reaching this limit. I expect we'll cut a release of it this week.

hev avatar Mar 19 '18 21:03 hev

@ahevenor Thank you for coming back to us and for implementing the fix. We are eager to try out the new version as soon as it has been released.

holgero avatar Mar 20 '18 08:03 holgero