feat(track2): add sequential per-chat message seeder
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"""Сидирует 100k сообщений в 24 чата с неравномерными размерами (трек 2)."""
|
||||
import base64
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
@@ -23,12 +24,29 @@ def make_user(c, label):
|
||||
return {'id': user['id'], 'username': username, 'token': s['token']}
|
||||
|
||||
|
||||
def seed_chat(base_url, ca_file, alice, bob, title, count):
|
||||
c = Client(base_url, ca_file)
|
||||
chat = c.call('POST', '/api/v1/chats', 201, actor=alice, body={
|
||||
'title': title, 'member_ids': [alice['id'], bob['id']]},
|
||||
schema='Chat')['json']
|
||||
chat_id = chat['id']
|
||||
|
||||
started = time.monotonic()
|
||||
for i in range(count):
|
||||
c.call('POST', f'/api/v1/chats/{chat_id}/messages', 201,
|
||||
actor=alice, body={'text': f'{title} #{i}'}, schema='Message')
|
||||
elapsed = time.monotonic() - started
|
||||
print(f' {title}: {count} сообщений за {elapsed:.1f}s')
|
||||
return chat_id
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments('Сидирует неравномерные чаты для трека 2')
|
||||
c = Client(args.base_url, args.ca_file)
|
||||
alice = make_user(c, 'track2_a')
|
||||
bob = make_user(c, 'track2_b')
|
||||
print(f'alice={alice["id"]} bob={bob["id"]}')
|
||||
|
||||
seed_chat(args.base_url, args.ca_file, alice, bob, 'hot', 1000)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user