Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

denopink
Copy link
Contributor

@denopink denopink commented Jun 5, 2024

  • 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))

- 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))
@denopink denopink self-assigned this Jun 5, 2024
@denopink denopink added the feature new functionality proposal/implementation label Jun 5, 2024
@denopink denopink force-pushed the denopink/feat/optimize-qos-trim-v2 branch from f86df03 to 5a4ec32 Compare June 5, 2024 22:19
@denopink denopink changed the title feat: optimize qos queue trimming (O(n*log(n)) feat: optimize qos queue trimming without heap.Init() (O(n*log(n)) Jun 5, 2024
priorityQueue
}

// Dequeue returns the message with the lowest QualityOfService.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Prioritize messages with the highest QualityOfService.
// Less prioritizes messages with the highest QualityOfService.

@denopink denopink closed this Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new functionality proposal/implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant