Home > Computers and Internet > Scalable Big doesn’t always mean Scalable Little

Scalable Big doesn’t always mean Scalable Little

Jeffery Reichter has me completly converted over to his asynchronous view of the computer world. Ideally, a process will never need more threads than there are cores on the machine. This, of course, isn’t the case. Nearly every application has way more threads than cores. The way to achieve this goal is to never have a thread block. So if the program is doing I/O, instead of waiting for the I/O device to finish the task, give it a delegate and tell it to call back when it’s done. Every example given deals with either, not blocking the UI thread, or being a scalable server application.
So imagine my frustration when I’m following all of the best practices, I profile my little, dumb application, and there seems to be an explosion of threads. I learned the reason why. I was under the understanding that the way the system was designed was that no threads would be waiting on the device and that when the device got back it triggered something in the Windows OS to respond to it. But that’s not what happens. What happens is when you (as the application) follow all of the correct asynchronous paradigms, that the system creates threads which waits on events. But wait! Wasn’t that supposed to be what I was trying to avoid? The answer is that the ThreadPool will dedicate a thread to wait for multiple events from multiple sources. Upto sixty four sources.
So in my app, yes, there’s an explosion of threads. The idea being that should the code be servicing thousands of clients that the same small subset of ThreadPool threads can serve up many, many requests.
It’s kind of upseting to learn that the computer wasn’t working as cool as I thought it was, but it’s still nice to know it’s scalable.
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: