Skip to content

Commit

Permalink
fix: remove thread_num
Browse files Browse the repository at this point in the history
  • Loading branch information
SpringMT committed Apr 12, 2024
1 parent d128f75 commit e399267
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
12 changes: 4 additions & 8 deletions benchmarks/multi_thread_comporess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'objspace'
require 'zstd-ruby'
require 'thread'
require "zstds"

GUESSES = (ENV['GUESSES'] || 1000).to_i
THREADS = (ENV['THREADS'] || 1).to_i
Expand All @@ -14,19 +15,14 @@
json_string = File.read("./samples/#{sample_file_name}")

queue = Queue.new
# queue = []
GUESSES.times { queue << json_string }
# stream = Zstd::StreamingCompress.new(thread_num: THREADS)
THREADS.times { queue << nil }
THREADS.times.map {
Thread.new {
while str = queue.pop
# stream = Zstd::StreamingCompress.new(thread_num: THREADS)
#stream << str
#stream << str
#stream << str
#stream.flush
Zstd.compress(str, thread_num: 1)
stream = Zstd::StreamingCompress.new
stream << str
stream.finish
end
}
}.each(&:join)
16 changes: 3 additions & 13 deletions ext/zstdruby/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ static size_t zstd_compress(ZSTD_CCtx* const ctx, ZSTD_outBuffer* output, ZSTD_i

static void set_compress_params(ZSTD_CCtx* const ctx, VALUE level_from_args, VALUE kwargs)
{
ID kwargs_keys[3];
ID kwargs_keys[2];
kwargs_keys[0] = rb_intern("level");
kwargs_keys[1] = rb_intern("dict");
kwargs_keys[2] = rb_intern("thread_num");
VALUE kwargs_values[3];
rb_get_kwargs(kwargs, kwargs_keys, 0, 3, kwargs_values);
VALUE kwargs_values[2];
rb_get_kwargs(kwargs, kwargs_keys, 0, 2, kwargs_values);

int compression_level = ZSTD_CLEVEL_DEFAULT;
if (kwargs_values[0] != Qundef && kwargs_values[0] != Qnil) {
Expand All @@ -68,15 +67,6 @@ static void set_compress_params(ZSTD_CCtx* const ctx, VALUE level_from_args, VAL
rb_raise(rb_eRuntimeError, "%s", "ZSTD_CCtx_loadDictionary failed");
}
}

if (kwargs_values[2] != Qundef && kwargs_values[2] != Qnil) {
int thread_num = NUM2INT(kwargs_values[2]);
size_t const r = ZSTD_CCtx_setParameter(ctx, ZSTD_c_nbWorkers, thread_num);
if (ZSTD_isError(r)) {
rb_warn("Note: the linked libzstd library doesn't support multithreading.Reverting to single-thread mode. \n");
}
// ZSTD_CCtx_setParameter(ctx, ZSTD_c_jobSize, thread_num);
}
}

static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
Expand Down
2 changes: 1 addition & 1 deletion ext/zstdruby/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

have_func('rb_gc_mark_movable')

$CFLAGS = '-I. -O3 -std=c99 -DZSTD_STATIC_LINKING_ONLY -DZSTD_MULTITHREAD -pthread'
$CFLAGS = '-I. -O3 -std=c99 -DZSTD_STATIC_LINKING_ONLY -DZSTD_MULTITHREAD -pthread -DDEBUGLEVEL=0'
$CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/

Dir.chdir File.expand_path('..', __FILE__) do
Expand Down

0 comments on commit e399267

Please sign in to comment.