Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More stats on coroutines #233

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions monocle/overseer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(self, manager):
self.things_count = deque(maxlen=9)
self.paused = False
self.coroutines_count = 0
self.time_diff = 0
self.spawn_counter = 0
self.mystery_counter = 0
self.skipped = 0
self.visits = 0
self.coroutine_semaphore = Semaphore(conf.COROUTINES_LIMIT, loop=LOOP)
Expand Down Expand Up @@ -171,11 +174,11 @@ def update_stats(self, refresh=conf.STAT_REFRESH, med=median, count=conf.GRID[0]
self.update_coroutines_count()
self.counts = (
'Known spawns: {}, unknown: {}, more: {}\n'
'{} workers, {} coroutines\n'
'{} workers, {} coroutines ({} on spawns, {} mysteries / more)\n'
'sightings cache: {}, mystery cache: {}, DB queue: {}\n'
).format(
len(spawns), len(spawns.unknown), spawns.cells_count,
count, self.coroutines_count,
count, self.coroutines_count, self.spawn_counter, self.mystery_counter,
len(SIGHTING_CACHE), len(MYSTERY_CACHE), len(db_proc)
)
LOOP.call_later(refresh, self.update_stats)
Expand Down Expand Up @@ -242,8 +245,10 @@ def _print_status(self, _ansi=ANSI, _start=datetime.now(), _notify=conf.NOTIFY):
self.counts,
self.stats,
self.pokemon_found,
('Visits: {}, per second: {:.2f}\n'
('Current time offset: {:.1f}\n'
'Visits: {}, per second: {:.2f}\n'
'Skipped: {}, unnecessary: {}').format(
self.time_diff,
self.visits, self.visits / seconds_since_start,
self.skipped, self.redundant)
]
Expand Down Expand Up @@ -406,9 +411,9 @@ async def _launch(self, update_spawns):

# negative = hasn't happened yet
# positive = already happened
time_diff = time() - spawn_time
self.time_diff = time() - spawn_time

while time_diff < 0.5:
while self.time_diff < 0.5:
try:
mystery_point = next(self.mysteries)

Expand All @@ -420,12 +425,12 @@ async def _launch(self, update_spawns):
self.next_mystery_reload = monotonic() + conf.RESCAN_UNKNOWN
else:
await sleep(min(spawn_time - time() + .5, self.next_mystery_reload - monotonic()), loop=LOOP)
time_diff = time() - spawn_time
self.time_diff = time() - spawn_time

if time_diff > 5 and spawn_id in SIGHTING_CACHE.store:
if self.time_diff > 5 and spawn_id in SIGHTING_CACHE.store:
self.redundant += 1
continue
elif time_diff > skip_spawn:
elif self.time_diff > skip_spawn:
self.skipped += 1
continue

Expand Down Expand Up @@ -501,6 +506,10 @@ async def bootstrap_try(point):

async def try_point(self, point, spawn_time=None):
try:
if spawn_time:
self.spawn_counter += 1
else:
self.mystery_counter += 1
point = randomize_point(point)
skip_time = monotonic() + (conf.GIVE_UP_KNOWN if spawn_time else conf.GIVE_UP_UNKNOWN)
worker = await self.best_worker(point, skip_time)
Expand All @@ -519,6 +528,10 @@ async def try_point(self, point, spawn_time=None):
except Exception:
self.log.exception('An exception occurred in try_point')
finally:
if spawn_time:
self.spawn_counter -= 1
else:
self.mystery_counter -= 1
self.coroutine_semaphore.release()

async def best_worker(self, point, skip_time):
Expand Down