Giter Club home page Giter Club logo

erlang-traffic-control's Introduction

Erlang traffic control

Build Status

A traffic control application written in erlang, you can use it to control the rate of flow, now it is implemented by using token buckets algorithm.

Two ways to use it

It can be used by block or non-block your application, and you can find demo in src/demo_worker.erl.

Block demo

start(Pid) ->
start(1000000, Pid).

start(N, Pid) ->
    spawn(fun() ->
        for(N, fun() -> tokens_queue:request_tokens(Pid) end)
    end).

for (0, _Func) ->
	ok;
for (N, Func) ->
	Func(),
	for (N - 1, Func).

Run block demo

{ok, Pid} = tokens_queue_manager:new_tokens_queue(100),
demo_worker:start(Pid).

%% show status
tokens_queue:infos(Pid).

Non-block demo

start_with_callback(Pid) ->
spawn(fun() ->
		Self = self(),
		tokens_queue:set_callback_function(Pid, fun() -> Self ! wakeup end),
		tokens_queue:request_tokens_cast(Pid),
		loop(Pid)
	end).

loop(Pid) ->
	receive
		wakeup ->
			tokens_queue:request_tokens_cast(Pid),
			loop(Pid);
		_Other ->
			io:format("I am fine!~n"),
			loop(Pid)
	end.

Run non-block demo

{ok, Pid} = tokens_queue_manager:new_tokens_queue(100),
UserPid = demo_worker:start_with_callback(Pid).

%% show status
tokens_queue:infos(Pid).

Unified MySQL Platform

This application is used in proxy module in Unified MySQL Platform from taobao to control sql query per second.

Important

If you want to use this application, please using branch stable.

TODO

  • Add a good tutorial.
  • Add a lisence file, maybe BSD like license is good choice.

erlang-traffic-control's People

Contributors

gaoyusong avatar

Watchers

James Cloos avatar Aleph Archives 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.