-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(workers) implement adaptive worker selection for improved task d…
…istribution (#589) * feat(worker-selection): Implement performance-based worker sorting - Add performance metrics fields to NodeData struct - Implement NodeSorter for flexible sorting of worker nodes - Create SortNodesByTwitterReliability function for Twitter workers - Update GetEligibleWorkerNodes to use category-specific sorting - Modify GetEligibleWorkers to use sorted workers and add worker limit This commit enhances the worker selection process by prioritizing workers based on their performance metrics. It introduces a flexible sorting mechanism that can be easily extended to other worker categories in the future. The changes improve reliability and efficiency in task allocation across the Masa Oracle network. * feat(worker-selection): Implement priority-based selection for Twitter work - Update DistributeWork to use priority selection for Twitter category - Maintain round-robin selection for other work categories by shuffling workers - Integrate new GetEligibleWorkers function with work type-specific behavior - Respect MaxRemoteWorkers limit for all work types - Add distinct logging for Twitter and non-Twitter worker selection This commit enhances the work distribution process by implementing priority-based worker selection for Twitter-related tasks while preserving the existing round-robin behavior for other work types. It leverages the newly added performance metrics to choose the most reliable workers for Twitter tasks, and ensures consistent behavior for other categories by shuffling the worker list. This hybrid approach improves efficiency for Twitter tasks while maintaining the expected behavior for all other work types. * Update .gitignore * feat(worker-selection): Implement priority-based sorting for Twitter workers - Add LastNotFoundTime and NotFoundCount fields to NodeData struct - Enhance SortNodesByTwitterReliability function with multi-criteria sorting: 1. Prioritize nodes found more often (lower NotFoundCount) 2. Consider recency of last not-found occurrence 3. Sort by higher number of returned tweets 4. Consider recency of last returned tweet 5. Prioritize nodes with fewer timeouts 6. Consider recency of last timeout 7. Use PeerId for stable sorting when no performance data is available - Remove random shuffling from GetEligibleWorkers function This commit improves worker selection for Twitter tasks by implementing a more sophisticated sorting algorithm that takes into account node reliability and performance metrics. It aims to enhance the efficiency and reliability of task distribution in the Masa Oracle network. * feat(worker-selection): Update Twitter fields in NodeData and Worker Manager Add functions to update Twitter-related metrics in NodeData and integrate updates into Worker Manager processes. This ensures accurate tracking of tweet-related events and peer activity in the system. * feat(worker-selection): Add unit tests for NodeData and NodeDataTracker Introduce unit tests for the NodeData and NodeDataTracker functionalities, covering scenarios involving updates to Twitter-related fields. These tests ensure the correctness of the UpdateTwitterFields method in NodeData and the UpdateNodeDataTwitter method in NodeDataTracker. * chore(workers): update timeouts and bump version --------- Co-authored-by: Bob Stevens <[email protected]>
- Loading branch information
1 parent
0ef0df4
commit f09fb20
Showing
10 changed files
with
286 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,4 @@ snippets.txt | |
|
||
# Build result of goreleaser | ||
dist/ | ||
bp-todo.md |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package node_data | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestNodeData(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "NodeData Test Suite") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package node_data | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/masa-finance/masa-oracle/pkg/pubsub" | ||
) | ||
|
||
var _ = Describe("NodeData", func() { | ||
Describe("UpdateTwitterFields", func() { | ||
It("should correctly update Twitter fields", func() { | ||
initialData := pubsub.NodeData{ | ||
ReturnedTweets: 10, | ||
TweetTimeouts: 2, | ||
NotFoundCount: 1, | ||
} | ||
|
||
updates := pubsub.NodeData{ | ||
ReturnedTweets: 5, | ||
LastReturnedTweet: time.Now(), | ||
TweetTimeout: true, | ||
TweetTimeouts: 1, | ||
LastTweetTimeout: time.Now(), | ||
LastNotFoundTime: time.Now(), | ||
NotFoundCount: 1, | ||
} | ||
|
||
initialData.UpdateTwitterFields(updates) | ||
|
||
Expect(initialData.ReturnedTweets).To(Equal(15)) | ||
Expect(initialData.TweetTimeouts).To(Equal(3)) | ||
Expect(initialData.NotFoundCount).To(Equal(2)) | ||
Expect(initialData.LastReturnedTweet.IsZero()).To(BeFalse()) | ||
Expect(initialData.LastTweetTimeout.IsZero()).To(BeFalse()) | ||
Expect(initialData.LastNotFoundTime.IsZero()).To(BeFalse()) | ||
}) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package node_data | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
. "github.com/masa-finance/masa-oracle/node" | ||
"github.com/masa-finance/masa-oracle/pkg/pubsub" | ||
) | ||
|
||
var _ = Describe("NodeDataTracker", func() { | ||
Context("UpdateNodeDataTwitter", func() { | ||
It("should correctly update NodeData Twitter fields", func() { | ||
testNode, err := NewOracleNode( | ||
context.Background(), | ||
EnableStaked, | ||
EnableRandomIdentity, | ||
) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = testNode.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
initialData := pubsub.NodeData{ | ||
PeerId: testNode.Host.ID(), | ||
LastReturnedTweet: time.Now().Add(-1 * time.Hour), | ||
ReturnedTweets: 10, | ||
TweetTimeout: true, | ||
TweetTimeouts: 2, | ||
LastTweetTimeout: time.Now().Add(-1 * time.Hour), | ||
LastNotFoundTime: time.Now().Add(-1 * time.Hour), | ||
NotFoundCount: 1, | ||
} | ||
|
||
err = testNode.NodeTracker.UpdateNodeDataTwitter(testNode.Host.ID().String(), initialData) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
updates := pubsub.NodeData{ | ||
ReturnedTweets: 5, | ||
LastReturnedTweet: time.Now(), | ||
TweetTimeout: true, | ||
TweetTimeouts: 1, | ||
LastTweetTimeout: time.Now(), | ||
LastNotFoundTime: time.Now(), | ||
NotFoundCount: 1, | ||
} | ||
|
||
err = testNode.NodeTracker.UpdateNodeDataTwitter(testNode.Host.ID().String(), updates) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
updatedData := testNode.NodeTracker.GetNodeData(testNode.Host.ID().String()) | ||
Expect(updatedData.ReturnedTweets).To(Equal(15)) | ||
Expect(updatedData.TweetTimeouts).To(Equal(3)) | ||
Expect(updatedData.NotFoundCount).To(Equal(2)) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.