Skip to content

bsc-s2/throttle_central

Repository files navigation

Table of Content

Name

throttle_central: A python lib used to set resource quota for each node.

Status

This library is in beta phase.

It has been used heavily in our object storage service, as a foundamental library of our devops platform.

Description

This lib must be used with lua-resty-throttle. The main purpose of this module is to find out how many resources each user have consumed on all nodes in every seconds, check if someone used too much, find out how many a user can use in next few seconds, also distribute the amount of resource usable by a user among all nodes.

Install

This package does not support installation.

Just clone it and copy it into your project source folder.

cd your_project_folder
git clone https://github.com/baishancloud/throttle_central.git

Usage

from throttle_central import manager

class ThrottleCentralLock(Object):
    def __enter__(self):
        print 'try to get lock'

    def __exit__(self, type, value, traceback):
        print 'release lock'

def list_limits(service_name):
    return [
        {
            # 'username' and 'limit' are mandatory
            'username': 'test_user',
            'limit': {
                'traffic_down': 1024,
                'database_read': 1024,
                'database_write': 1024,
                'traffic_up': 10240,
             },
            'ts': '1513681047768',
            'service': 'front',
        },
    ]


argkv = {
    'ip': '127.0.0.1',
    'port': 7075,
    'nr_slot': 60,
    'Lock': ThrottleCentralLock,
    'list_limits': list_limits,
}

manager.run(**argkv)

Update sub repo

You do not need to read this chapter if you are not a maintainer.

First update sub repo config file .gitsubrepo and run git-subrepo.

git-subrepo will fetch new changes from all sub repos and merge them into current branch mater:

./script/git-subrepo/git-subrepo

git-subrepo is a tool in shell script. It merges sub git repo into the parent git working dir with git-submerge.

Methods

throttle_central.manager.run

Start the service

prototype

throttle_central.manager.run(**argkv)

arguments

It receive the following arguments:

  • argkv is a dict contains some optional arguments. It can contains the following arguments:

    • ip the ip address to listen on for receiving info reported by node module.

    • port the socket port to use.

    • nr_slot set how many slots to keep, default is 60.

    • Lock a lock class that can be used in a 'with' statement, for high reliability, we need to set up several central node, but only the node which got lock will actually do work.

    • list_limits a callback function used to get all limit settings for a service, the prototype is: list_limits(service_name)

Author

Renzhi (任稚) [email protected]

Copyright and License

The MIT License (MIT)

Copyright (c) 2016 Renzhi (任稚) [email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages