Added worker display and made interlacing bigger

This commit is contained in:
Casey 2024-07-09 19:00:34 +03:00
parent b1860ce065
commit d667e8ffd2
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 28 additions and 24 deletions

View File

@ -27,15 +27,16 @@ class WorkerManager:
self.shmem_name = shmem_name self.shmem_name = shmem_name
self.base = "https://onemillioncheckboxes.com" self.base = "https://onemillioncheckboxes.com"
self.delay = 0.25 self.delay = 0.25
self.queue: asyncio.Queue[int] = asyncio.Queue(64) self.queue: asyncio.Queue[int] = asyncio.Queue(128)
self.n_toggles = 0 self.n_toggles = 0
self.workers: set[tuple[int, int]] = set()
async def queue_manager(self): async def queue_manager(self):
offset = random.randint(0, 999999) offset = random.randint(0, 999999)
while True: while True:
for oy in [0, 4, 2, 6, 1, 3, 5, 7]: for oy in [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]:
for y in range(oy, 1000, 8): for y in range(oy, 1000, 16):
for x in range(1000): for x in range(1000):
index = (x + y * 1000 + offset) % 1000000 index = (x + y * 1000 + offset) % 1000000
byte, bit = divmod(index, 8) byte, bit = divmod(index, 8)
@ -58,10 +59,11 @@ class WorkerManager:
sio = socketio.AsyncClient(http_session=http) sio = socketio.AsyncClient(http_session=http)
async def writer_itself(): async def writer_itself():
print("Writer running")
while not sio.connected: while not sio.connected:
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
print("Connected and running") cookie = bot_index, random.randint(0, 9999)
self.workers.add(cookie)
try:
while sio.connected: while sio.connected:
index = await self.queue.get() index = await self.queue.get()
byte, bit = divmod(index, 8) byte, bit = divmod(index, 8)
@ -81,7 +83,8 @@ class WorkerManager:
self.shmem.buf[OFFSET_STATE + byte] ^= 0x80 >> bit self.shmem.buf[OFFSET_STATE + byte] ^= 0x80 >> bit
await sio.emit("toggle_bit", {"index": index}) await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(self.delay) await asyncio.sleep(self.delay)
print("Writer closed") finally:
self.workers.remove(cookie)
sio.on("connect", writer_itself) sio.on("connect", writer_itself)
@ -95,6 +98,7 @@ class WorkerManager:
diff = time.time() - last_printout diff = time.time() - last_printout
print() print()
print(f"Workers: {len(self.workers)}")
print(f"Queue size: {self.queue.qsize()}/{self.queue.maxsize}") print(f"Queue size: {self.queue.qsize()}/{self.queue.maxsize}")
print(f"Toggles: {self.n_toggles / diff:.2f}/s") print(f"Toggles: {self.n_toggles / diff:.2f}/s")