From 98bd9830da7071eed71c95611da7ef8a5f1cf71e Mon Sep 17 00:00:00 2001 From: Susant Palai Date: Mon, 4 May 2015 16:43:02 +0530 Subject: dht/rebalance: Throttle rebalance Throttle value will be "normal" by default. For throttling down, a thread will be put in to sleep. And for throttling up, gf_defrag_process_dir will wake up the sleeping threads. Change-Id: I74d530e3effd6e60e6eec81ccc8ff65789fa9c13 Signed-off-by: Susant Palai Reviewed-on: http://review.gluster.org/10526 Reviewed-by: Raghavendra G Tested-by: Raghavendra G --- xlators/cluster/dht/src/dht-shared.c | 61 ++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'xlators/cluster/dht/src/dht-shared.c') diff --git a/xlators/cluster/dht/src/dht-shared.c b/xlators/cluster/dht/src/dht-shared.c index 3b22a2a8486..0ab81c37890 100644 --- a/xlators/cluster/dht/src/dht-shared.c +++ b/xlators/cluster/dht/src/dht-shared.c @@ -15,11 +15,32 @@ #endif /* TODO: add NS locking */ - +#include #include "statedump.h" #include "dht-common.h" #include "dht-messages.h" +#define MAX(a, b) (((a) > (b))?(a):(b)) + +#define GF_DECIDE_DEFRAG_THROTTLE_COUNT(throttle_count, conf) { \ + \ + pthread_mutex_lock (&conf->defrag->dfq_mutex); \ + \ + if (!strcasecmp (conf->dthrottle, "lazy")) \ + conf->defrag->recon_thread_count = 1; \ + \ + throttle_count = MAX ((get_nprocs() - 4), 4); \ + \ + if (!strcasecmp (conf->dthrottle, "normal")) \ + conf->defrag->recon_thread_count = \ + (throttle_count / 2); \ + \ + if (!strcasecmp (conf->dthrottle, "aggressive")) \ + conf->defrag->recon_thread_count = \ + throttle_count; \ + \ + pthread_mutex_unlock (&conf->defrag->dfq_mutex); \ + } \ /* TODO: - use volumename in xattr instead of "dht" @@ -374,6 +395,7 @@ dht_reconfigure (xlator_t *this, dict_t *options) char *temp_str = NULL; gf_boolean_t search_unhashed; int ret = -1; + int throttle_count = 0; GF_VALIDATE_OR_GOTO ("dht", this, out); GF_VALIDATE_OR_GOTO ("dht", options, out); @@ -426,6 +448,16 @@ dht_reconfigure (xlator_t *this, dict_t *options) conf->randomize_by_gfid, options, bool, out); + GF_OPTION_RECONF ("rebal-throttle", conf->dthrottle, options, + str, out); + + if (conf->defrag) { + GF_DECIDE_DEFRAG_THROTTLE_COUNT (throttle_count, conf); + gf_log ("DHT", GF_LOG_INFO, "conf->dthrottle: %s, " + "conf->defrag->recon_thread_count: %d", + conf->dthrottle, conf->defrag->recon_thread_count); + } + if (conf->defrag) { GF_OPTION_RECONF ("rebalance-stats", conf->defrag->stats, options, bool, out); @@ -534,7 +566,7 @@ dht_init (xlator_t *this) gf_defrag_info_t *defrag = NULL; int cmd = 0; char *node_uuid = NULL; - + int throttle_count = 0; GF_VALIDATE_OR_GOTO ("dht", this, err); @@ -604,6 +636,8 @@ dht_init (xlator_t *this) pthread_mutex_init (&defrag->dfq_mutex, 0); pthread_cond_init (&defrag->parallel_migration_cond, 0); pthread_cond_init (&defrag->rebalance_crawler_alarm, 0); + pthread_cond_init (&defrag->df_wakeup_thread, 0); + defrag->global_error = 0; } @@ -710,6 +744,17 @@ dht_init (xlator_t *this) GF_OPTION_INIT ("randomize-hash-range-by-gfid", conf->randomize_by_gfid, bool, err); + if (defrag) { + GF_OPTION_INIT ("rebal-throttle", + conf->dthrottle, str, err); + + GF_DECIDE_DEFRAG_THROTTLE_COUNT(throttle_count, conf); + + gf_log ("DHT", GF_LOG_DEBUG, "conf->dthrottle: %s, " + "conf->defrag->recon_thread_count: %d", + conf->dthrottle, conf->defrag->recon_thread_count); + } + GF_OPTION_INIT ("xattr-name", conf->xattr_name, str, err); gf_asprintf (&conf->link_xattr_name, "%s."DHT_LINKFILE_STR, conf->xattr_name); @@ -922,5 +967,17 @@ struct volume_options options[] = { "subvolume to which it hashes" }, + { .key = {"rebal-throttle"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "normal", + .description = " Sets the maximum number of parallel file migrations " + "allowed on a node during the rebalance operation. The" + " default value is normal and allows a max of " + "[($(processing units) - 4) / 2), 2] files to be " + "migrated at a time. Lazy will allow only one file to " + "be migrated at a time and aggressive will allow " + "max of [($(processing units) - 4) / 2), 4]" + }, + { .key = {NULL} }, }; -- cgit