Skip to content

Instantly share code, notes, and snippets.

@agentgt
Created February 1, 2015 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agentgt/74f7b23b6cf42882c1c0 to your computer and use it in GitHub Desktop.
Save agentgt/74f7b23b6cf42882c1c0 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type ThreadConfig struct {
MaxThreads int
CorePoolSize int
Consumers int
TxSize int
QueueSize int
}
func NewThreadConfig() *ThreadConfig {
return &ThreadConfig{
MaxThreads: 8,
CorePoolSize: 1,
Consumers: 1,
TxSize: 1,
}
}
func NormalizeConfig(config *ThreadConfig) {
totalItems := config.TxSize * config.Consumers
queueSize := 0
if totalItems > config.MaxThreads {
queueSize = config.TxSize * config.Consumers
}
config.QueueSize = queueSize
}
func main() {
config := NewThreadConfig()
config.TxSize = 20
config.Consumers = 2
NormalizeConfig(config)
fmt.Println("Hello, world ", config.QueueSize)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment