From 715f36ca8165d3d89f974567c883dfb0e2bc4e36 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Wed, 26 Jul 2017 15:52:15 -0700 Subject: [PATCH] added definitions for conversion constants, moved forced compression check to top of adaptCompressionLevel, used ZSTD_BLOCKSIZE_MAX --- contrib/adaptive-compression/adapt.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/contrib/adaptive-compression/adapt.c b/contrib/adaptive-compression/adapt.c index 5ff2e418..05da8b7f 100644 --- a/contrib/adaptive-compression/adapt.c +++ b/contrib/adaptive-compression/adapt.c @@ -28,6 +28,8 @@ #define MAX_COMPRESSION_LEVEL_CHANGE 2 #define CONVERGENCE_LOWER_BOUND 5 #define CLEVEL_DECREASE_COOLDOWN 5 +#define CHANGE_BY_TWO_THRESHOLD 0.1 +#define CHANGE_BY_ONE_THRESHOLD 0.65 #ifndef DEBUG_MODE static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; @@ -322,10 +324,10 @@ static void waitUntilAllJobsCompleted(adaptCCtx* ctx) /* map completion percentages to values for changing compression level */ static unsigned convertCompletionToChange(double completion) { - if (completion < 0.1) { + if (completion < CHANGE_BY_TWO_THRESHOLD) { return 2; } - else if (completion < 0.65) { + else if (completion < CHANGE_BY_ONE_THRESHOLD) { return 1; } else { @@ -350,6 +352,13 @@ static void adaptCompressionLevel(adaptCCtx* ctx) double const threshold = 0.00001; unsigned const prevCompressionLevel = ctx->compressionLevel; + + if (g_forceCompressionLevel) { + ctx->compressionLevel = g_compressionLevel; + return; + } + + DEBUG(2, "adapting compression level %u\n", ctx->compressionLevel); /* read and reset completion measurements */ @@ -420,10 +429,6 @@ static void adaptCompressionLevel(adaptCCtx* ctx) if (ctx->compressionLevel == prevCompressionLevel) { ctx->convergenceCounter++; } - - if (g_forceCompressionLevel) { - ctx->compressionLevel = g_compressionLevel; - } } static size_t getUseableDictSize(unsigned compressionLevel) @@ -500,7 +505,7 @@ static void* compressionThread(void* arg) DEBUG(2, "job %u compressed with level %u\n", currJob, ctx->compressionLevel); /* compress the data */ { - size_t const compressionBlockSize = 1 << 17; /* 128 KB */ + size_t const compressionBlockSize = ZSTD_BLOCKSIZE_MAX; /* 128 KB */ unsigned const cLevel = ctx->compressionLevel; unsigned blockNum = 0; size_t remaining = job->src.size;