Git Product home page Git Product logo

docker-cpu-agent's Introduction

aasmith/cpu-agent

A tiny docker image for advertising the amount of CPU idle cycles that are available.

Why

Load balancers, such as haproxy can make weighting decisions based on the CPU load of the servers in a given backend. (See agent-check in the haproxy docs.)

Details

The container runs sar, a tool for sampling CPU availability. This is served up as a integer percentage using netcat.

CPU idle is never advertised to be below 1%. HAProxy (and possibly other consumers) take action beyond simple weighting at this level.

The CPU sample is run on-demand, so there is a one second delay while the sample is taken. An instant read would use the average idle time since machine start, which is not desirable.

Running

The image will need access to the host's pid list, so run the container as such:

$ docker run -p 40000:40000 --pid=host aasmith/cpu-agent

To test output, try the following (your variety of netcat may vary):

$ ncat --recv-only 127.0.0.1 40000
99%

Example

For an example of a complete use case, see the examples directory for a haproxy config that uses an agent to achieve weighted-round-robin load balancing.

Real-World Usage

Google advocates for Weighted Round Robin with per-node CPU polling in Site Reliability Engineering:

Weighted Round Robin is an important load balancing policy that improves on Simple and Least-Loaded Round Robin by incorporating backend-provided information into the decision process.

Weighted Round Robin is fairly simple in principle: each client task keeps a "capability" score for each backend in its subset. Requests are distributed in Round-Robin fashion, but clients weigh the distributions of requests to backends proportionally. In each response (including responses to health checks), backends include the current observed rates of queries and errors per second, in addition to the utilization (typically, CPU usage). Clients adjust the capability scores periodically to pick backend tasks based upon their current number of successful requests handled and at what utilization cost; failed requests result in a penalty that affects future decisions.

In practice, Weighted Round Robin has worked very well and significantly reduced the difference between the most and the least utilized tasks.

docker-cpu-agent's People

Contributors

aasmith avatar

Watchers

 avatar  avatar

docker-cpu-agent's Issues

Smooth reported numbers when idle increases

When a node is overloaded, the node will report a very low idle number. The consumer, such a proxy will back off connections significantly to help reduce workload on the node. Once this work is complete, the node will likely be very idle, as the upstream proxy will not be sending in many connections. The node will then report 99 idle or something very high. If the node is somewhat degraded, it may not be able to handle peak load, that it will now certainly get from the proxy. It will report near zero and perform below average, continuing this whipsaw effect.

The proposed solution is to gradually report an increase in idle over a given number of samples, therefore allowing the proxy to ramp traffic gradually and discover the right load for the node.

Pick a port number

Small detail, but the internal port should be something sensible, not 12345.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.