MCPcopy Create free account
hub / github.com/deepflowio/deepflow / NewOverwriteQueues

Function NewOverwriteQueues

server/libs/queue/multi_queue.go:65–87  ·  view source on GitHub ↗

count和queueSize要求是2的幂以避免求余计算,如果不是2的幂将会隐式转换为2的幂来构造 HashKey要求映射到count范围内,否则MultiQueue只会取低比特位

(module string, count uint8, queueSize int, options ...Option)

Source from the content-addressed store, hash-verified

63// count和queueSize要求是2的幂以避免求余计算,如果不是2的幂将会隐式转换为2的幂来构造
64// HashKey要求映射到count范围内,否则MultiQueue只会取低比特位
65func NewOverwriteQueues(module string, count uint8, queueSize int, options ...Option) FixedMultiQueue {
66 if count > MAX_QUEUE_COUNT {
67 panic(fmt.Sprintf("queueCount超出最大限制%d", MAX_QUEUE_COUNT))
68 }
69
70 size := int(count)
71 queues := make([]*OverwriteQueue, size)
72 for i := 0; i < size; i++ {
73 opts := append(options, stats.OptionStatTags{"index": strconv.Itoa(i)})
74 queue := new(OverwriteQueue)
75 queue.Init(module, queueSize, opts...)
76 queues[i] = queue
77 }
78 tableSize := 1
79 for tableSize < size {
80 tableSize <<= 1
81 }
82 table := make(FixedMultiQueue, tableSize)
83 for i := 0; i < tableSize; i++ {
84 table[i] = queues[i%size]
85 }
86 return table
87}

Callers 1

TestMultiQueueFunction · 0.85

Calls 1

InitMethod · 0.65

Tested by 1

TestMultiQueueFunction · 0.68