joonspk-research / generative_agents

Generative Agents: Interactive Simulacra of Human Behavior
Apache License 2.0
16.26k stars 2.09k forks source link

Frontend page freezing? Some suggestions. #76

Open 2043078895 opened 1 year ago

2043078895 commented 1 year ago

Environment Description: The backend is deployed on an Amazon server, and the frontend web page runs on a Mac, resulting in significant network communication costs. I often experience freezing when using "run xxx". After some investigation, I found that it may be related to the continuous refreshing of the frontend. The frontend web page continuously calls the backend's "/update_environment" API after launching "http://xxxx:8000/simulator_home". If the refresh frequency is too high, the backend may not be able to keep up with the processing capacity (possibly due to network IO limitations). This can cause certain errors related to JSON file read/write operations, resulting in abnormal termination of the game process. The frontend page uses the Parser game framework for page rendering, reference:https://github.com/joonspk-research/generative_agents/blob/main/environment/frontend_server/templates/home/main_script.html#L79 During the rendering process, the "update" function is called continuously, reference:https://github.com/joonspk-research/generative_agents/blob/main/environment/frontend_server/templates/home/main_script.html#L332 To reduce the update frequency, I made the following changes to the "update" function: var flush_counter = 0; function update(time, delta) { if(flush_counter < 50){ flush_counter += 1; return ; } else{ flush_counter = 0; } ………… After restarting the process, everything is functioning normally again!

image
2043078895 commented 1 year ago

By the way, I must say that after switching to gpt-3.5-turbo, the cost has indeed been significantly reduced!

10cl commented 1 year ago

16.6ms each time, change this will affect the frame rate of the animation drawing and affect the animation effect

nyoma-diamond commented 9 months ago

A much better solution I just found for these problems is to set a specific cap for the framerate of the simulation. See: https://github.com/joonspk-research/generative_agents/issues/137#issuecomment-1868091513

Tl;dr unrestricted framerate can completely saturate the network with excessive requests. Capping the framerate limits the number of requests. Solution is to edit the config variable in main_script.html with something like this:

fps: {
    target: 15,
    forceSetTimeOut: true
}