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.base = "https://onemillioncheckboxes.com"
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.workers: set[tuple[int, int]] = set()
async def queue_manager(self):
offset = random.randint(0, 999999)
while True:
for oy in [0, 4, 2, 6, 1, 3, 5, 7]:
for y in range(oy, 1000, 8):
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, 16):
for x in range(1000):
index = (x + y * 1000 + offset) % 1000000
byte, bit = divmod(index, 8)
@ -58,30 +59,32 @@ class WorkerManager:
sio = socketio.AsyncClient(http_session=http)
async def writer_itself():
print("Writer running")
while not sio.connected:
await asyncio.sleep(0.1)
print("Connected and running")
while sio.connected:
index = await self.queue.get()
byte, bit = divmod(index, 8)
mask = 0x80 >> bit
if self.shmem.buf[OFFSET_AVOID + byte] & mask:
continue
if (self.shmem.buf[OFFSET_MASK + byte] & mask) == 0:
continue
if (self.shmem.buf[OFFSET_CANVAS + byte] & mask) != (
self.shmem.buf[OFFSET_STATE + byte] & mask
):
cookie = bot_index, random.randint(0, 9999)
self.workers.add(cookie)
try:
while sio.connected:
index = await self.queue.get()
byte, bit = divmod(index, 8)
self.n_toggles += 1
self.shmem.buf[OFFSET_STATE + byte] ^= 0x80 >> bit
await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(self.delay)
print("Writer closed")
mask = 0x80 >> bit
if self.shmem.buf[OFFSET_AVOID + byte] & mask:
continue
if (self.shmem.buf[OFFSET_MASK + byte] & mask) == 0:
continue
if (self.shmem.buf[OFFSET_CANVAS + byte] & mask) != (
self.shmem.buf[OFFSET_STATE + byte] & mask
):
byte, bit = divmod(index, 8)
self.n_toggles += 1
self.shmem.buf[OFFSET_STATE + byte] ^= 0x80 >> bit
await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(self.delay)
finally:
self.workers.remove(cookie)
sio.on("connect", writer_itself)
@ -95,6 +98,7 @@ class WorkerManager:
diff = time.time() - last_printout
print()
print(f"Workers: {len(self.workers)}")
print(f"Queue size: {self.queue.qsize()}/{self.queue.maxsize}")
print(f"Toggles: {self.n_toggles / diff:.2f}/s")