Added worker display and made interlacing bigger
This commit is contained in:
parent
b1860ce065
commit
d667e8ffd2
|
@ -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,30 +59,32 @@ 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)
|
||||||
while sio.connected:
|
self.workers.add(cookie)
|
||||||
index = await self.queue.get()
|
try:
|
||||||
byte, bit = divmod(index, 8)
|
while sio.connected:
|
||||||
mask = 0x80 >> bit
|
index = await self.queue.get()
|
||||||
|
|
||||||
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)
|
byte, bit = divmod(index, 8)
|
||||||
self.n_toggles += 1
|
mask = 0x80 >> bit
|
||||||
self.shmem.buf[OFFSET_STATE + byte] ^= 0x80 >> bit
|
|
||||||
await sio.emit("toggle_bit", {"index": index})
|
if self.shmem.buf[OFFSET_AVOID + byte] & mask:
|
||||||
await asyncio.sleep(self.delay)
|
continue
|
||||||
print("Writer closed")
|
|
||||||
|
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)
|
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")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue