Module: GC::OOB
- Defined in:
- lib/gctools/oobgc/puma_middleware.rb,
lib/gctools/oobgc/unicorn_middleware.rb,
ext/oobgc/oobgc.c
Defined Under Namespace
Modules: UnicornMiddleware
Classes: PumaMiddleware
Class Method Summary
collapse
Class Method Details
.clear ⇒ Object
176
177
178
179
180
181
|
# File 'ext/oobgc/oobgc.c', line 176
static VALUE
oobgc_clear(VALUE self)
{
MEMZERO(&_oobgc.stat, _oobgc.stat, 1);
return Qnil;
}
|
.run ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'ext/oobgc/oobgc.c', line 106
static VALUE
oobgc(VALUE self)
{
size_t curr = rb_gc_stat(sym_total_allocated_object);
if (!_oobgc.installed) install();
if (!_oobgc.prev_allocated_object) {
_oobgc.prev_allocated_object = curr;
} else {
size_t diff = curr - _oobgc.prev_allocated_object;
_oobgc.prev_allocated_object = curr;
if (_oobgc.threshold.mean)
_oobgc.threshold.mean = (diff / 4) + (_oobgc.threshold.mean * 3 / 4);
else
_oobgc.threshold.mean = diff;
if (diff > _oobgc.threshold.max)
_oobgc.threshold.max = diff;
if (_oobgc.threshold.max > 200000)
_oobgc.threshold.max = 200000;
}
if (_oobgc.sweep_needed) {
/* lazy sweep started sometime recently.
* disable/enable the GC to force gc_rest_sweep() OOB
*/
if (rb_gc_disable() == Qfalse) rb_gc_enable();
_oobgc.stat.sweep++;
return Qtrue;
} else if (_oobgc.allocation_limit) {
/* GC will be required when total_allocated_object gets
* close to allocation_limit
*/
if ((rb_gc_stat(sym_old_object) >= rb_gc_stat(sym_old_object_limit)*0.97 ||
rb_gc_stat(sym_remembered_shady_object) >= rb_gc_stat(sym_remembered_shady_object_limit)*0.97) &&
curr >= _oobgc.allocation_limit - _oobgc.threshold.max*0.98) {
/*fprintf(stderr, "oobgc MAJOR: %zu >= %zu - %zu\n", curr, _oobgc.allocation_limit, _oobgc.threshold.max);*/
gc_start_major();
return Qtrue;
} else if (curr >= _oobgc.allocation_limit - _oobgc.threshold.mean) {
/*fprintf(stderr, "oobgc minor: %zu >= %zu - %zu\n", curr, _oobgc.allocation_limit, _oobgc.threshold.mean);*/
gc_start_minor();
return Qtrue;
}
}
return Qfalse;
}
|
.setup ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'ext/oobgc/oobgc.c', line 67
static VALUE
install()
{
rb_event_flag_t events =
RUBY_INTERNAL_EVENT_GC_START |
RUBY_INTERNAL_EVENT_GC_END_MARK |
RUBY_INTERNAL_EVENT_GC_END_SWEEP;
if (_oobgc.installed)
return Qfalse;
if (!_oobgc.tpval) {
_oobgc.tpval = rb_tracepoint_new(0, events, gc_event_i, (void *)0);
rb_ivar_set(mOOB, rb_intern("tpval"), _oobgc.tpval);
}
rb_tracepoint_enable(_oobgc.tpval);
_oobgc.installed = 1;
return Qtrue;
}
|
.stat(key) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'ext/oobgc/oobgc.c', line 158
static VALUE
oobgc_stat(VALUE self, VALUE key)
{
if (!_oobgc.installed)
return Qnil;
if (key == sym_count)
return SIZET2NUM(_oobgc.stat.major + _oobgc.stat.minor + _oobgc.stat.sweep);
else if (key == sym_major_count)
return SIZET2NUM(_oobgc.stat.major);
else if (key == sym_minor_count)
return SIZET2NUM(_oobgc.stat.minor);
else if (key == sym_sweep_count)
return SIZET2NUM(_oobgc.stat.sweep);
else
return Qnil;
}
|