charlesbaynham / wurwolves

2 stars 0 forks source link

Speed testing #118

Closed charlesbaynham closed 3 years ago

charlesbaynham commented 3 years ago

After lots of faffing around in #119, I'm back to speed profiling.

With code at fd783d8a09e00aa72f822d9e68bbb9ff4e3336ed, I can run

pytest -k test_state_speed --log-format="%(asctime)s.%(msecs)03d  %(levelname)s %(message)s"  > live_db_test.log 

to profile the speed of state rendering and can alter .env to

...
IGNORE_TESTING_DB=true
DATABASE_URL=postgres://some_real_db_with_username_and_password_on_AWS
...

To run my local tests against a real PostgreSQL database.

Doing so, I get 2700ms per state, compared to 150ms per state with a local SQLite database.

charlesbaynham commented 3 years ago

That would be the problem behind #111

charlesbaynham commented 3 years ago

live_db_test.log

Logs for the above test. These show 312 commits to the database and 571 selects, just for joining and rendering states for 10 players. That's 57 database queries per render, and 31 writes. eeek!

charlesbaynham commented 3 years ago

N.B. setting debug level back to INFO and removing sqlalchemy logging, I still get 2.656 per state, so barely any difference.

charlesbaynham commented 3 years ago

In 50c28f8, test_state_speed reports for 5x players in a game (n.b. previous stats were for 10x)

WARNING  root:test_backend.py:82 time_per_join = 0.754s of which 0.548s in 17.6 DB calls
WARNING  root:test_backend.py:85 time_per_render = 1.446s of which 1.020s in 29.0 DB calls
charlesbaynham commented 3 years ago

Not finished, but this is an improvement. On version fb169e1 I'm down to

WARNING  root:test_backend.py:82 time_per_join = 0.923s of which 0.817s in 12.0 DB calls
WARNING  root:test_backend.py:85 time_per_render = 0.915s of which 0.685s in 22.0 DB calls

Merging into master for now, but I should continue later.