1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

chore: collection size (#3844)

This commit is contained in:
Vladislav 2024-10-08 18:51:11 +03:00 committed by GitHub
parent 50a7f2bcb1
commit 786c9cd44d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 10 deletions

View file

@ -79,6 +79,7 @@ class StaticSeeder(SeederBase):
data_size=100, data_size=100,
variance=5, variance=5,
samples=10, samples=10,
collection_size=None,
types: typing.Optional[typing.List[str]] = None, types: typing.Optional[typing.List[str]] = None,
): ):
SeederBase.__init__(self, types) SeederBase.__init__(self, types)
@ -87,6 +88,11 @@ class StaticSeeder(SeederBase):
self.variance = variance self.variance = variance
self.samples = samples self.samples = samples
if collection_size is None:
self.collection_size = data_size ** (1 / 3)
else:
self.collection_size = collection_size
async def run(self, client: aioredis.Redis): async def run(self, client: aioredis.Redis):
"""Run with specified options until key_target is met""" """Run with specified options until key_target is met"""
samples = [ samples = [
@ -105,9 +111,9 @@ class StaticSeeder(SeederBase):
dsize = random.uniform(self.data_size / self.variance, self.data_size * self.variance) dsize = random.uniform(self.data_size / self.variance, self.data_size * self.variance)
csize = 1 csize = 1
else: else:
dsize = self.data_size ** (1 / 3) csize = self.collection_size
dsize = random.uniform(dsize / self.variance, dsize * self.variance) csize = math.ceil(random.uniform(csize / self.variance, csize * self.variance))
csize = int(self.data_size // dsize) + 1 dsize = self.data_size // csize
args = ["DEBUG", "POPULATE", key_target, prefix, math.ceil(dsize)] args = ["DEBUG", "POPULATE", key_target, prefix, math.ceil(dsize)]
args += ["RAND", "TYPE", dtype, "ELEMENTS", csize] args += ["RAND", "TYPE", dtype, "ELEMENTS", csize]
@ -124,14 +130,26 @@ class Seeder(SeederBase):
units: typing.List[Unit] units: typing.List[Unit]
def __init__(self, units=10, key_target=10_000, data_size=100): def __init__(
SeederBase.__init__(self) self,
units=10,
key_target=10_000,
data_size=100,
collection_size=None,
types: typing.Optional[typing.List[str]] = None,
):
SeederBase.__init__(self, types)
self.key_target = key_target self.key_target = key_target
self.data_size = data_size self.data_size = data_size
if collection_size is None:
self.collection_size = math.ceil(data_size ** (1 / 3))
else:
self.collection_size = collection_size
self.units = [ self.units = [
Seeder.Unit( Seeder.Unit(
prefix=f"k-s{self.uid}u{i}-", prefix=f"k-s{self.uid}u{i}-",
type=Seeder.DEFAULT_TYPES[i % len(Seeder.DEFAULT_TYPES)], type=self.types[i % len(self.types)],
counter=0, counter=0,
stop_key=f"_s{self.uid}u{i}-stop", stop_key=f"_s{self.uid}u{i}-stop",
) )
@ -147,6 +165,7 @@ class Seeder(SeederBase):
target_ops if target_ops is not None else 0, target_ops if target_ops is not None else 0,
target_deviation if target_deviation is not None else -1, target_deviation if target_deviation is not None else -1,
self.data_size, self.data_size,
self.collection_size,
] ]
sha = await client.script_load(Seeder._load_script("generate")) sha = await client.script_load(Seeder._load_script("generate"))

View file

@ -17,12 +17,13 @@ local key_target = tonumber(ARGV[5])
local total_ops = tonumber(ARGV[6]) local total_ops = tonumber(ARGV[6])
local min_dev = tonumber(ARGV[7]) local min_dev = tonumber(ARGV[7])
local data_size = tonumber(ARGV[8]) local data_size = tonumber(ARGV[8])
local collection_size = tonumber(ARGV[9])
-- collect all keys belonging to this script -- collect all keys belonging to this script
-- assumes exclusive ownership -- assumes exclusive ownership
local keys = LU_collect_keys(prefix, type) local keys = LU_collect_keys(prefix, type)
LG_funcs.init(data_size) LG_funcs.init(data_size, collection_size)
local addfunc = LG_funcs['add_' .. string.lower(type)] local addfunc = LG_funcs['add_' .. string.lower(type)]
local modfunc = LG_funcs['mod_' .. string.lower(type)] local modfunc = LG_funcs['mod_' .. string.lower(type)]

View file

@ -1,9 +1,9 @@
local LG_funcs = {} local LG_funcs = {}
function LG_funcs.init(dsize) function LG_funcs.init(dsize, csize)
LG_funcs.dsize = dsize LG_funcs.dsize = dsize
LG_funcs.csize = math.floor(dsize ^ (2/3)) LG_funcs.csize = csize
LG_funcs.esize = math.ceil(dsize ^ (1/3)) LG_funcs.esize = math.ceil(dsize / csize)
end end
-- strings -- strings

View file

@ -14,6 +14,26 @@ async def test_static_seeder(async_client: aioredis.Redis):
assert abs(await async_client.dbsize() - 10_000) <= 50 assert abs(await async_client.dbsize() - 10_000) <= 50
@dfly_args({"proactor_threads": 4})
async def test_static_collection_size(async_client: aioredis.Redis):
async def check_list():
keys = await async_client.keys()
assert (await async_client.llen(keys[0])) == 1
assert len(await async_client.lpop(keys[0])) == 10_000
s = StaticSeeder(
key_target=10, data_size=10_000, variance=1, samples=1, collection_size=1, types=["LIST"]
)
await s.run(async_client)
await check_list()
await async_client.flushall()
s = Seeder(units=1, key_target=10, data_size=10_000, collection_size=1, types=["LIST"])
await s.run(async_client)
await check_list()
@dfly_args({"proactor_threads": 4}) @dfly_args({"proactor_threads": 4})
async def test_seeder_key_target(async_client: aioredis.Redis): async def test_seeder_key_target(async_client: aioredis.Redis):
"""Ensure seeder reaches its key targets""" """Ensure seeder reaches its key targets"""