Giter Club home page Giter Club logo

http-server-stabilizer's Introduction

http-server-stabilizer

Here's the situation:

  • You've got an HTTP server that generally works quite well.
  • Sometimes, it goes rogue and consumes 100% of a CPU as it gets stuck into a loop. You will track down and fix this, but in the meantime it shouldn't harm other requests.

http-server-stabilizer solves this problem by doing three simple things:

  1. Running multiple copies of your HTTP server and acting as a reverse-proxy to them.
  2. Dividing requests do the copies randomly.
  3. When a request takes longer than a specified amount of time, that server subprocess is restarted.

Installation

Install Go, then:

go get -u github.com/slimsag/http-server-stabilizer

See the releases tab for prebuilt linux/amd64 binaries.

Usage

http-server-stabilizer [options] -- yourcommand -youroption true

Consult http-server-stabilizer -h for options.

Demo

The following starts an HTTP server which responds to GET / requests and randomly consumes 100% CPU:

http-server-stabilizer -demo -demo-listen ':9091'

If you make multiple curl http://localhost:9091 requests, you'll find the web server quickly consumes all available CPUs. Making use of http-server-stabilizer, we can prevent this:

http-server-stabilizer -- http-server-stabilizer -demo -demo-listen ':{{.Port}}'

The -timeout=10s flag can be used to control how long rogue requests can go for. You can also control the timeout via a request header: X-Stabilize-Timeout: 20s.

Debugging

All responses include a X-Worker header which is a PID correlating to the http-server-stabilizer worker PID for debugging purposes (so you can trace a specific request back to a specific worker process).

A Prometheus metric indicating how many worker restarts occur is also exposed at :6060/metrics. For example, with -prometheus-app-name="myapp" the metric myapp_hss_worker_restarts will be exposed.

http-server-stabilizer's People

Contributors

slimsag avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

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.