-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: optimize qos queue trimming without heap.Init()
(O(n*log(n)
)
#154
Conversation
- 100% test cover for internal/wrphandlers/qos - optimize priorityQueue.trim() to remove messages with the lowest qos by leveraging two priority queues (1 prioritizing the highest QOS and the other prioritizing the lowest QOS) - avoid the use of `heap.Init()` O(n) - priorityQueue.trim() is O(n*log(n))
f86df03
to
5a4ec32
Compare
O(n*log(n)
)heap.Init()
(O(n*log(n)
)
priorityQueue | ||
} | ||
|
||
// Dequeue returns the message with the lowest QualityOfService. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Dequeue returns the message with the lowest QualityOfService. | |
// trim removes the message with the lowest QualityOfService. |
|
||
// heap.Interface related implementation https://pkg.go.dev/container/heap#Interface | ||
|
||
// Prioritize messages with the lowest QualityOfService. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Prioritize messages with the lowest QualityOfService. | |
// Less prioritizes messages with the lowest QualityOfService. |
} | ||
|
||
// heap.Interface related implementations https://pkg.go.dev/container/heap#Interface | ||
func (pq *priorityQueue) Len() int { return len(pq.queue) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (pq *priorityQueue) Len() int { return len(pq.queue) } | |
func (pq *priorityQueue) Len() int { return len(pq.queue) } |
|
||
func (pq *priorityQueue) Less(i, j int) bool { | ||
iItem, jItem := pq.queue[i], pq.queue[j] | ||
// Prioritize messages with the highest QualityOfService. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Prioritize messages with the highest QualityOfService. | |
// Less prioritizes messages with the highest QualityOfService. |
heap.Init()
O(n)