Multithreading

Options
ddks
edited March 2012 in Photon Server
Hi,

What is the threading model behind the scenes? I am working on adding in a mechanism to sync cached data inside photon to a database and basically I have 3 options:
1) i implement a simply void function inside one of my sub servers that i call every x seconds and that loops the cache and syncs stuff to the db. Pretty straight forward just not sure how the execution would be handled from a threading perspective (i assume it is on the main application thread)
2) i implement a thread pool queue (assuming the above wouldn't be async) and do it that way. so my sub server would add a new function to be executed by the thread pool (static). Logging will be harder to see.
3) setup a seperate application inside photon and have that handle the sync so all this application does is sync cache to db

Any comments from any one? Usually simpler is better for me and having central logging is also good so option 1 or 3 would be my preference. I do have a full blow option 2 class code so it is pretty simple to implement as well.

Thanks,
Dan

Comments

  • ddks
    Options
    Thought i update my own thread.

    For now I am going ahead with option #2. Given that I already wrote my own thread pool, including priority queuing and also being able to remove items from the queue (which i why wrote the pool in the first place).

    Right now i use a simple Timer inside one of my sub servers, when the timer ticks I add a sync-cache-to-db worker thread to my threadpool. this thread will simply go through one of my caches (e.g. a players-cache) and update the database. I will do sync x number of players to sync to the db and stop. Then the next time the timer ticks the thread is being added again.

    Not sure if I will get into a conflict and need to add some lock to avoid thread access errors (given that the cache can be updated from multiple threads I suspect this is going to be needed)

    Dan