Skip to content

Conversation

@goktuggurler
Copy link

The call from SimpleLoadBalancer to DegraderStrategy passes a Map<URI, TrackerClient> object for the getTrackerClient() method to handle load balancing. This object was being converted to List<DegraderTrackerClient> using castToDegraderTrackerClients() method. However, during the load balancing operation, this casting operation was not needed. This PR aims to rectify that. The PR also have positive impact on getRing() method which was suffering from the same process.

We have updated the unit tests accordingly.


private List<DegraderTrackerClient> castToDegraderTrackerClients(Map<URI, TrackerClient> trackerClients)
{
List<DegraderTrackerClient> degraderTrackerClients = new ArrayList<>(trackerClients.size());
Copy link
Author

Choose a reason for hiding this comment

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

Memory allocation followed by O(N) operations.

}

List<DegraderTrackerClient> degraderTrackerClients = castToDegraderTrackerClients(trackerClients);
Collection<TrackerClient> trackerClientList = trackerClients.values();
Copy link
Author

Choose a reason for hiding this comment

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

castToDegraderTrackerClients return an empty list if trackerClients cannot be cast to DegradedTrackerClient. This is to mimic that behavior.

if (excludedUris == null)
{
excludedUris = new HashSet<>();
excludedUris = Collections.emptySet();
Copy link
Author

Choose a reason for hiding this comment

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

Avoid another unnecessary memory allocation.

warn(_log, "Can not find hash ring to use");
}

Map<URI, DegraderTrackerClient> trackerClientMap = new HashMap<>(trackerClients.size());
Copy link
Author

Choose a reason for hiding this comment

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

Another memory allocation followed by O(N) complexity.

}

private DegraderTrackerClient searchClientFromUri(URI uri, List<DegraderTrackerClient> trackerClients)
private DegraderTrackerClient searchClientFromUri(URI uri, Map<URI, TrackerClient> trackerClients)
Copy link
Author

Choose a reason for hiding this comment

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

When it is a map, we do the search in O(1) time rather than O(N).

* Whether to force update
* @return True if we should update, and false otherwise.
*/
protected static boolean shouldUpdatePartition(long clusterGenerationId, PartitionDegraderLoadBalancerState partitionState,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create a new method and call the new one from the old? This is a protected method and we'd like backwards compatibility.

Copy link
Author

Choose a reason for hiding this comment

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

Kept the old one and created the overloaded version of it. The old one does the conversion (inefficient but still accessible).

Copy link
Contributor

@shivamgupta1 shivamgupta1 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants