Skip to content

Commit c277524

Browse files
authored
Merge pull request #45 from SpringMT/fix/fix-SEGV-when-gc-at-streaming
fix segv bugs when gc at streaming
2 parents 99e951d + 2de307f commit c277524

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'benchmark/ips'
2+
3+
$LOAD_PATH.unshift '../lib'
4+
5+
require 'json'
6+
require 'objspace'
7+
require 'zstd-ruby'
8+
9+
p "#{ObjectSpace.memsize_of_all/1000} #{ObjectSpace.count_objects} #{`ps -o rss= -p #{Process.pid}`.to_i}"
10+
11+
sample_file_name = ARGV[0]
12+
13+
json_string = IO.read("./samples/#{sample_file_name}")
14+
15+
i = 0
16+
while true do
17+
stream = Zstd::StreamingCompress.new
18+
stream << json_string[0, 5]
19+
res = stream.flush
20+
stream << json_string[5..-1]
21+
res << stream.finish
22+
if ((i % 1000) == 0 )
23+
GC.start
24+
puts "count:#{i}\truby_memory:#{ObjectSpace.memsize_of_all/1000}\tobject_count:#{ObjectSpace.count_objects}\trss:#{`ps -o rss= -p #{Process.pid}`.to_i}"
25+
end
26+
i += 1
27+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'benchmark/ips'
2+
3+
$LOAD_PATH.unshift '../lib'
4+
5+
require 'json'
6+
require 'zstd-ruby'
7+
require 'objspace'
8+
9+
p "#{ObjectSpace.memsize_of_all/1000} #{ObjectSpace.count_objects} #{`ps -o rss= -p #{Process.pid}`.to_i}"
10+
11+
sample_file_name = ARGV[0]
12+
13+
cstr = IO.read("./results/#{sample_file_name}.zstd")
14+
i = 0
15+
while true do
16+
stream = Zstd::StreamingDecompress.new
17+
result = ''
18+
result << stream.decompress(cstr[0, 10])
19+
result << stream.decompress(cstr[10..-1])
20+
21+
if ((i % 1000) == 0 )
22+
GC.start
23+
puts "count:#{i}\truby_memory:#{ObjectSpace.memsize_of_all/1000}\tobject_count:#{ObjectSpace.count_objects}\trss:#{`ps -o rss= -p #{Process.pid}`.to_i}"
24+
end
25+
i += 1
26+
end

ext/zstdruby/streaming_compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ rb_streaming_compress_initialize(int argc, VALUE *argv, VALUE obj)
5858

5959
int compression_level;
6060
if (NIL_P(compression_level_value)) {
61-
compression_level = 0; // The default. See ZSTD_CLEVEL_DEFAULT in zstd_compress.c
61+
compression_level = ZSTD_CLEVEL_DEFAULT;
6262
} else {
6363
compression_level = NUM2INT(compression_level_value);
6464
}

ext/zstdruby/streaming_decompress.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ struct streaming_decompress_t {
66
size_t buf_size;
77
};
88

9-
static void
10-
streaming_decompress_mark(void *p)
11-
{
12-
struct streaming_decompress_t *sd = p;
13-
// rb_gc_mark((VALUE)sd->ctx);
14-
rb_gc_mark(sd->buf);
15-
rb_gc_mark(sd->buf_size);
16-
}
17-
189
static void
1910
streaming_decompress_free(void *p)
2011
{
@@ -34,7 +25,7 @@ streaming_decompress_memsize(const void *p)
3425

3526
static const rb_data_type_t streaming_decompress_type = {
3627
"streaming_decompress",
37-
{ streaming_decompress_mark, streaming_decompress_free, streaming_decompress_memsize, },
28+
{ 0, streaming_decompress_free, streaming_decompress_memsize, },
3829
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3930
};
4031

0 commit comments

Comments
 (0)