Jump to content
  • Advertisement
Sign in to follow this  
vinnyvicious

Proper output buffering algorithm

This topic is 797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, i'm working on a small multi-threaded game server. Currently, there is a finite amount of threads and each of them are taking care of different tasks. So, the whole loop is naturally thread-safe. Unfortunately, there are a few parts of the application that threads need to share. Logging, for example. I have an unordered_map<string, ostringstream> static variable that i use for logging stuff dynamically. At the end of each loop iteration, i have condition to check the size of the ostringstream, and if it's higher than X, i save it to disk. This way, i'm only offloading logs to disk a few times, not on every frame.

 

The problem is: when the loop is idle, waiting for commands, the log can be "stuck". If the ostringstream is lower than X, and i go to an idle state, then it keeps there forever, never offloading to disk the last parts of the log. Right now, i've made another thread that runs on intervals, responsible for checking if the size of the buffer has changed or not. If it hasn't changed for a long, it dumps it.

 

But is there a better way of handling this?

Share this post


Link to post
Share on other sites
Advertisement

Can you make the loop's idle state have a timeout - so while waiting for commands, it will also wake up on it's own if no command is received within a certain amount of time?

Share this post


Link to post
Share on other sites

The loop is based on libev, so i tried the timeout feature, but it didn't work very well. Timeouts were never triggered because, well, there was no timeout going on. I've also tried libev's idle callback, but it runs too many times, to the point where my conditional for the size of the buffer was affecting performance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!