1 / 51

Multi-Threading and Load Balancing

Multi-Threading and Load Balancing. Compiled by Paul TaylorCSE3AGR Stolen mainly from Orion Granatir http://www.gamasutra.com/php-bin/article_display.php?story=4006. What changed?. Single Thread Computer games have been used since day 0 The person to blame is Gordon Moore*

more
Download Presentation

Multi-Threading and Load Balancing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multi-Threading and Load Balancing Compiled by Paul TaylorCSE3AGR Stolen mainly from Orion Granatir http://www.gamasutra.com/php-bin/article_display.php?story=4006

  2. What changed? • Single Thread Computer games have been used since day 0 • The person to blame is Gordon Moore* * Not really it just feels good to blame someone!

  3. Moore’s Law • The Complexity of IC’s will go up exponentially • We mutilated this into CPU speed will increase expo. • This all F*#ked up a few years ago when we started pushing the boundaries of transistor miniaturisation • To keep the processing increase we went with Multi core processors • http://en.wikipedia.org/wiki/File:Transistor_Count_and_Moore%27s_Law_-_2008.svg

  4. It all goes bad.... • http://www.gamasutra.com/php-bin/article_display.php?story=4006

  5. Multi-Core and Threading • http://www.gamasutra.com/php-bin/article_display.php?story=4006

  6. Network Assimilation • http://www.gamasutra.com/php-bin/article_display.php?story=4006

  7. Processes and Threads

  8. The first crappy threading code you’ll see CATCTATCATTCTATCTACTATCATCTACTATCTACTATCTACTCTTACTCAT

  9. Distributing Load (You need to manage your employees)

  10. That was a better Threading ModelBut still not good enough for today's machines

  11. Distributing Load even more!

  12. Learning to ShareAll cats need the Shovel for their Quest

  13. Learning to ShareCat has the Shovel

  14. Learning to ShareCat has the Loot

  15. This is what Thread Locking is for Now how do we go about locking them??

  16. Option 1: Critical Sections • When one thread enters the critical section, the others will have to wait......

  17. Critical Sections • And wait....

  18. And wait...

  19. Option1: Critical Sections THE RULES • Keep them small!!! • A lot of CPU time can be wasted waiting.... And waiting...

  20. Option #2: Mutexsand Semaphores

  21. Mutexs and Semaphores

  22. Mutexs and Semaphores

  23. Mutexs and Semaphores

  24. Mutexs and Semaphores • A Semaphore is like using Multiple tokens (it retains a count) • Critical Sections are fastest, but limited to one process • Mutexs are slower, but globally accessible • Semaphores are great for things like allocating your memory buffers

  25. Events

  26. Events

  27. Events

  28. Events

  29. Events

  30. Events

  31. Atomic Operations • http://www.breadonthewaters.com/add/0888_nuclear_explosion_large_clipart.jpg

  32. Atomic Operations 5 + 1 + 1 + 1 = 8

  33. Atomic Operations 5 + 1 + 1 + 1 = 6!!

  34. Atomic Operations • This is why we need atomic operations

  35. Atomic Operations • This is why we need atomic operations

  36. ThreadingNightmares http://ioconnor.files.wordpress.com/2009/09/danger1.jpg

  37. Deadlocks

  38. Deadlocks

  39. Deadlocks

  40. Race Conditions • The ‘race’ is a term for when your code expects threads to return in order, and they don’t!!!

  41. Race Conditions

  42. Race Conditions

  43. Race Conditions

  44. Network Code Example

  45. A Good use of Threading... ....

  46. Network Code Example

  47. Network Code Example

  48. Network Code Example

  49. Network Code Example

  50. Network Code Example Issues • The Main thread would then need to wait for all Network threads to finish before it resets the NetworkUpdateEvent and continues • How would you solve this issue?

More Related