diff options
author | Venky Shankar <vshankar@redhat.com> | 2015-04-17 15:00:13 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2015-05-07 07:14:32 -0700 |
commit | 4c6e9c5f8d62444412c86545868cdb5bf6a06b39 (patch) | |
tree | 524afb5cd7058e3d8ce071258a70e18ca269b9a8 /xlators/features/bit-rot/src/bitd/bit-rot-tbf.h | |
parent | aa938247e19afa419476fb2d0b7cb2d054c6dd47 (diff) |
features/bit-rot: Token Bucket based throttling
BitRot daemons (signer & scrubber) are disk/cpu hoggers when left
running full throttle. Checksum calculations (especially SHA family
of hash routines) can be quite CPU intensive. Moreover periodic
disk scans performed by scrubber followed by reading data blocks
for hash calculation (which is also done by signer) generate lot
of heavy IO request(s). This causes interference with actual client
operations (be it a regular client or filesystems daemons such as
self-heal, etc..) and results in degraded system performance.
This patch introduces throttling based on Token Bucket Filtering[1].
It's a well known algorithm for checking (and ensuring) that data
transmission conform to defined limits and generally used in packet
switched networks. Linux control groups (Cgroups) uses a variant[2]
of this algorithm to provide block device IO throttling (cgroup
subsys "blkio": blk-iothrottle).
So, why not just live with Cgroups?
Cgroups is linux specific. We need to have a throttling mechanism
for other supported UNIXes. Moreover, having our own implementation
gives much more finer control in terms of tuning it for our needs
(plus the simplicity of the alogorithm itself).
Ideally, throttling should be a part of server stack (either as a
separate translator or integrated with io-threads) since that's
the point of entry for IO request(s) from *all* client(s). That
way one could selectively throttle IO request(s) based on client
PIDs (frame->root->pid), e.g., self-heal daemon, bitrot, etc..
(*actual* clients can run full throttle). This implementation
avoids that deliberately (there needs to be a much more smarter
queueing mechanism) and throttles CPU usage for hash calculations.
This patch is just the infrastructure part with no interfaces
exposed to set various throttling values. The tunable selected
here (basically hardcoded) avoids 100% CPU usage during hash
calculation (with some bursts cycles). We'd need much more
intensive test(s) to assign values for various throttling
options (lazy/normal/aggressive).
[1] https://en.wikipedia.org/wiki/Token_bucket
[2] http://en.wikipedia.org/wiki/Token_bucket#Hierarchical_token_bucket
Change-Id: Icc49af80eeab6adb60166d0810e69ef37cfe2fd8
BUG: 1207020
Signed-off-by: Venky Shankar <vshankar@redhat.com>
Reviewed-on: http://review.gluster.org/10307
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Tested-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/features/bit-rot/src/bitd/bit-rot-tbf.h')
-rw-r--r-- | xlators/features/bit-rot/src/bitd/bit-rot-tbf.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-tbf.h b/xlators/features/bit-rot/src/bitd/bit-rot-tbf.h new file mode 100644 index 00000000000..5a41be4fd95 --- /dev/null +++ b/xlators/features/bit-rot/src/bitd/bit-rot-tbf.h @@ -0,0 +1,70 @@ +/* + Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#include "list.h" +#include "xlator.h" +#include "locking.h" + +#ifndef __BIT_ROT_TBF_H__ +#define __BIT_ROT_TBF_H__ + +typedef enum br_tbf_ops { + BR_TBF_OP_MIN = -1, + BR_TBF_OP_HASH = 0, /* checksum calculation */ + BR_TBF_OP_READ = 1, /* inode read(s) */ + BR_TBF_OP_READDIR = 2, /* dentry read(s) */ + BR_TBF_OP_MAX = 3, +} br_tbf_ops_t; + +/** + * Operation rate specification + */ +typedef struct br_tbf_opspec { + br_tbf_ops_t op; + + unsigned long rate; + + unsigned long maxlimit; +} br_tbf_opspec_t; + +/** + * Token bucket for each operation type + */ +typedef struct br_tbf_bucket { + gf_lock_t lock; + + pthread_t tokener; /* token generator thread */ + + unsigned long tokenrate; /* token generation rate */ + + unsigned long tokens; /* number of current tokens */ + + unsigned long maxtokens; /* maximum token in the bucket */ + + struct list_head queued; /* list of non-conformant requests */ +} br_tbf_bucket_t; + +typedef struct br_tbf { + br_tbf_bucket_t **bucket; +} br_tbf_t; + +br_tbf_t * +br_tbf_init (br_tbf_opspec_t *, unsigned int); + +int +br_tbf_mod (br_tbf_t *, br_tbf_opspec_t *); + +void +br_tbf_throttle (br_tbf_t *, br_tbf_ops_t, unsigned long); + +#define TBF_THROTTLE_BEGIN(tbf, op, tokens) (br_tbf_throttle (tbf, op, tokens)) +#define TBF_THROTTLE_END(tbf, op, tokens) (void) + +#endif /** __BIT_ROT_TBF_H__ */ |