Save every program execution time to new table 'execution_time'
This commit is contained in:
pare
93b3a4334c
commit
5ba03a1c86
S'han modificat 2 arxius amb 91 adicions i 7 eliminacions
46
fediverse.py
46
fediverse.py
|
@ -445,6 +445,36 @@ def usage():
|
|||
print('usage: python ' + sys.argv[0] + ' --multi' + ' (multiprocessing, fast)')
|
||||
print('usage: python ' + sys.argv[0] + ' --mono' + ' (one process, slow)')
|
||||
|
||||
def save_time(program, start, finish):
|
||||
|
||||
insert_sql = "INSERT INTO execution_time(program, start, finish) VALUES(%s,%s,%s) ON CONFLICT DO NOTHING"
|
||||
|
||||
conn = None
|
||||
|
||||
try:
|
||||
|
||||
conn = psycopg2.connect(database = fediverse_db, user = fediverse_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
||||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute(insert_sql, (program, start, finish,))
|
||||
|
||||
cur.execute("UPDATE execution_time SET start=(%s), finish=(%s) where program=(%s)", (start, finish, program))
|
||||
|
||||
conn.commit()
|
||||
|
||||
cur.close()
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
||||
print(error)
|
||||
|
||||
finally:
|
||||
|
||||
if conn is not None:
|
||||
|
||||
conn.close()
|
||||
|
||||
def get_parameter(parameter, file_path):
|
||||
|
||||
# Check if secrets file exists
|
||||
|
@ -474,6 +504,14 @@ if __name__ == '__main__':
|
|||
|
||||
if sys.argv[1] == '--multi':
|
||||
|
||||
start = datetime.now()
|
||||
|
||||
program = 'fediverse'
|
||||
|
||||
finish = start
|
||||
|
||||
save_time(program, start, finish)
|
||||
|
||||
now = datetime.now()
|
||||
|
||||
mastodon, mastodon_hostname = mastodon()
|
||||
|
@ -492,11 +530,11 @@ if __name__ == '__main__':
|
|||
|
||||
getservers.now = datetime.now()
|
||||
|
||||
start = time.time()
|
||||
ray_start = time.time()
|
||||
|
||||
results = ray.get([getservers.get_alive_servers.remote(server) for server in alive_servers])
|
||||
|
||||
print(f"duration = {time.time() - start}.\nprocessed servers: {len(results)}")
|
||||
print(f"duration = {time.time() - ray_start}.\nprocessed servers: {len(results)}")
|
||||
|
||||
###########################################################################
|
||||
# get current total servers and users, get users from every software
|
||||
|
@ -838,6 +876,10 @@ if __name__ == '__main__':
|
|||
|
||||
delete_dead_servers()
|
||||
|
||||
finish = datetime.now()
|
||||
|
||||
save_time(program, start, finish)
|
||||
|
||||
else:
|
||||
|
||||
usage()
|
||||
|
|
|
@ -340,6 +340,36 @@ def get_world_servers():
|
|||
|
||||
return world_servers
|
||||
|
||||
def save_time(program, start, finish):
|
||||
|
||||
insert_sql = "INSERT INTO execution_time(program, start, finish) VALUES(%s,%s,%s) ON CONFLICT DO NOTHING"
|
||||
|
||||
conn = None
|
||||
|
||||
try:
|
||||
|
||||
conn = psycopg2.connect(database = fediverse_db, user = fediverse_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
||||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute(insert_sql, (program, start, finish,))
|
||||
|
||||
cur.execute("UPDATE execution_time SET start=(%s), finish=(%s) where program=(%s)", (start, finish, program))
|
||||
|
||||
conn.commit()
|
||||
|
||||
cur.close()
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
||||
print(error)
|
||||
|
||||
finally:
|
||||
|
||||
if conn is not None:
|
||||
|
||||
conn.close()
|
||||
|
||||
def get_parameter(parameter, file_path):
|
||||
|
||||
# Check if secrets file exists
|
||||
|
@ -379,16 +409,28 @@ if __name__ == '__main__':
|
|||
|
||||
## name: fetchservers.py
|
||||
|
||||
now = datetime.now()
|
||||
fediverse_db, fediverse_db_user = get_db_config()
|
||||
|
||||
start = datetime.now()
|
||||
|
||||
program = 'fetchservers'
|
||||
|
||||
finish = start
|
||||
|
||||
save_time(program, start, finish)
|
||||
|
||||
now = start
|
||||
|
||||
mastodon_hostname = get_config()
|
||||
|
||||
fediverse_db, fediverse_db_user = get_db_config()
|
||||
|
||||
world_servers = get_world_servers()
|
||||
|
||||
start = time.time()
|
||||
ray_start = time.time()
|
||||
|
||||
results = ray.get([getsoft.remote(server) for server in world_servers])
|
||||
|
||||
print(f"duration = {time.time() - start}.\nprocessed servers: {len(results)}")
|
||||
print(f"duration = {time.time() - ray_start}.\nprocessed servers: {len(results)}")
|
||||
|
||||
finish = datetime.now()
|
||||
|
||||
save_time(program, start, finish)
|
||||
|
|
Loading…
Referencia en una nova incidència