awolden / brakes

Hystrix compliant Node.js Circuit Breaker Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CPU growth

bdfinst opened this issue · comments

Using the default setting, we experienced growth in CPU usage and increasing performance degradation throughout the day. We were forced to add a cron job to bounce the service every 6 hours. When I removed brakes, CPU usage returned to normal.

Hi @YamatoMan,

Sorry to hear you are having troubles with Brakes. I haven't seen any rise in CPU usage using brakes in my services, so I would be interested to know more about how it is being implemented in your application. Can you provide some more details on how you are implementing it?

Thanks,

-Alex

@YamatoMan Hopefully this message finds you well. I was able to reproduce a very similar issue by instantiating new brakes instances in the request handler for a service. This was causing run away CPU growth as a new circuit breaker instance was being created for every request. I'm not sure if this was causing your issue, but I hope the information might be helpful.

Here's how we're implementing

function circuitBreakify(fnToWrap) {
    const brake = new brakes(fnToWrap);
    return brake;
}
.
.
.
function getInfoForThing(req, thing) {
    const request = httpHelper.circuitBreakify(getInfoForThingRequest);
    return request.exec(req, thing);
    return getInfoForThingRequest(req, thing);
}

So, we're doing exactly what you said. How would you recommend we implement instead?

Thanks!

You will want to create 1 brakes instance for every function you want to circuit break, and stick it in a reference-able spot.

Something like this:

// create each circuit exactly once some where else in your app or module
const circuits = {
  getInfoForThingRequest: new Brakes(fnToWrap);
}

...
...

function getInfoForThing(req, thing) {
    // do not create a circuit per request, instead exec a previously instantiated circuit.
    return circuits.getInfoForThingRequest.exec(req, thing);
}