Created
February 1, 2015 17:23
-
-
Save agentgt/74f7b23b6cf42882c1c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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