feat(twitter): Enhanced Twitter Worker Selection Algorithm #591
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements an improved worker selection algorithm for Twitter tasks in the Masa Oracle project. The goal is to balance between prioritizing high-performing workers and ensuring fair work distribution.
Key Changes
1. Modified
GetEligibleWorkers
function (pkg/workers/worker_selection.go
)pubsub.CategoryTwitter
)2. New
getTwitterWorkers
function (pkg/workers/worker_selection.go
)3. New
calculatePoolSize
function (pkg/workers/worker_selection.go
)4. New
SortNodesByTwitterReliability
function (pkg/pubsub/node_event_tracker.go
)5. Updated
NodeEventTracker.GetEligibleWorkerNodes
(pkg/pubsub/node_event_tracker.go
)SortNodesByTwitterReliability
for the Twitter category6. Enhanced logging
logrus
for debugging and monitoringImplementation Details
Twitter Worker Selection Process
NodeTracker.GetEligibleWorkerNodes(category)
a. Calculate pool size using
calculatePoolSize
b. Select top performers based on the calculated pool size
c. Shuffle the selected top performers
d. Create Worker objects from the shuffled pool, respecting the original limit
Node Sorting for Twitter Reliability
The
SortNodesByTwitterReliability
function uses a multi-criteria approach to rank nodes:Benefits
TODO
Testing