Skip to content

Commit f57e7ea

Browse files
fiber.yield() call removed from quantile (#241)
1 parent 18fb2ee commit f57e7ea

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Fixed
99
- cpu metrics hot reload [#228](https://github.com/tarantool/metrics/issues/228)
1010
- cartridge metrics role fails to start without http [#225](https://github.com/tarantool/metrics/issues/225)
11+
- quantile overflow after `fiber.yield()` [#235](https://github.com/tarantool/metrics/issues/235)
1112

1213
## [0.8.0] - 2021-04-13
1314
### Added

metrics/quantile.lua

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
local fiber = require('fiber')
21
local ffi = require('ffi')
32

43
local quantile = {}
54

6-
ffi.cdef[[
7-
typedef struct {int Delta, Width; double Value; } sample;
8-
]]
5+
if not pcall(ffi.typeof, "sample") then
6+
ffi.cdef[[
7+
typedef struct sample {int Delta, Width; double Value; } sample;
8+
]]
9+
end
910

1011
local sample_constructor = ffi.typeof('sample')
1112

@@ -134,9 +135,6 @@ function stream:merge(samples, len)
134135
local i = 1
135136
local r = 0
136137
for z = 1, len do
137-
if i % 1000 == 0 then
138-
fiber.yield()
139-
end
140138
local sample = samples[z-1]
141139
for j = i, s.l_len do
142140
local c = s.l[j]
@@ -165,9 +163,6 @@ function stream:query(q)
165163
local p = s.l[0]
166164
local r = 0
167165
for i = 1, s.l_len do
168-
if i % 500 == 0 then
169-
fiber.yield()
170-
end
171166
local c = s.l[i]
172167
if r + c.Width + c.Delta > t then
173168
return p.Value
@@ -189,9 +184,6 @@ function stream:compress()
189184
local r = s.n - x.Width
190185

191186
for i = s.l_len - 1, 1, -1 do
192-
if i % 1000 == 0 then
193-
fiber.yield()
194-
end
195187
local c = make_sample(0)
196188
sample_copy(c, s.l[i])
197189
if c.Width + x.Width + x.Delta <= s.f(s, r) then

test/quantile_test.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local quantile = require('metrics.quantile')
2+
local fiber = require('fiber')
23
local ffi = require('ffi')
34
local t = require('luatest')
45
local g = t.group('quantile')
@@ -104,3 +105,21 @@ g.test_package_reload = function()
104105
local ok, quantile_package = pcall(require, 'metrics.quantile')
105106
t.assert(ok, quantile_package)
106107
end
108+
109+
g.test_fiber_yield = function()
110+
local q1 = quantile.NewTargeted({[0.5]=0.01, [0.9]=0.01, [0.99]=0.01}, 1000)
111+
112+
for _=1,10 do
113+
fiber.create(function()
114+
for _=1,1e2 do
115+
t.assert(q1.b_len < q1.__max_samples)
116+
quantile.Insert(q1, math.random(1000))
117+
end
118+
end)
119+
end
120+
121+
for _=1,10 do
122+
t.assert(q1.b_len < q1.__max_samples)
123+
quantile.Insert(q1, math.random(1))
124+
end
125+
end

0 commit comments

Comments
 (0)