# Thread Pooling in Go Programming

DevFeed: [Thread Pooling in Go Programming](<https://devfeed.tech/articles/thread-pooling-in-go-programming-22045.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/05/thread-pooling-in-go-programming.html>)

Published: 2013-05-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [servers](<https://devfeed.tech/topics/servers.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [.NET](<https://devfeed.tech/topics/net.md>), [C#](<https://devfeed.tech/topics/csharp.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [win32](<https://devfeed.tech/topics/win32.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [development](<https://devfeed.tech/tags/development.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [goroutines](<https://devfeed.tech/tags/goroutines.md>), [process](<https://devfeed.tech/tags/process.md>), [programming](<https://devfeed.tech/tags/programming.md>), [server](<https://devfeed.tech/tags/server.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threads](<https://devfeed.tech/tags/threads.md>), [win32](<https://devfeed.tech/tags/win32.md>)

## AI overview

This article introduces thread pools for server development and discusses how to tune pool size and concurrency. It describes queuing work for a fixed number of worker threads, explains why creating a new thread for every task can harm performance, and relates the approach to Go goroutines and unbuffered channels, with comparisons to Microsoft-stack development.

## Source excerpt

After working in Go for some time now, I learned how to use an unbuffered channel to build a pool of goroutines. I like this implementation better than what is implemented in this post. That being said, this post still has value in what it describes. External resource on github.com: https://github.com/goinggo/work Introduction In my world of server development thread pooling has been the key to building robust code on the Microsoft stack. Microsoft has failed in .Net by giving each Process a single thread pool with thousands of threads and thinking they could manage the concurrency at runtime. Early on I realized this was never going to work. At least not for the servers I was developing. When I was building servers in C/C++ using the Win32 API, I created a class that abstracted IOCP to give me thread pools I could post work into. This has always worked very well because I could define the number of threads in the pool and the concurrency level (the number of threads allowed to be active at any given time). I ported this code for all of my C# development. If you want to learn more about this, I wrote an article years ago (External resource on theukwebdesigncompany.com: http://www.theukwebdesigncompany.com/articles/iocp-thread-pooling.php). Using IOCP gave me the performance and flexibility I needed. BTW, the .NET thread pool uses IOCP underneath. The idea of the thread pool is fairly simple. Work comes into the server and needs to get processed. Most of this work is asynchronous in nature but it doesn't have to be. Many times the work is coming off a socket or from an internal routine. The thread pool queues up the work and then a thread from the pool is assigned to perform the work. The work is processed in the order it was received. The pool provides a great pattern for performing work efficiently. Spawning a new thread everytime work needs to be processed can put heavy loads on the operating system and cause major performance problems. So how is the thread pool p