-
Notifications
You must be signed in to change notification settings - Fork 24
Refactor Service routing into separate router classes #172
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
Conversation
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.
great start!!!
def get_replica( | ||
self, | ||
replicas: List["Replica"], | ||
sess_id: str | None = None, |
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.
sess_id: str,
i.e. don't assume None
is passable for this or session_map
. I would also get rid of the checks below
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.
This is because I have a interface for routers: (also see interface.py
)
class Router(ABC):
"""Abstract base class for routing logic."""
@abstractmethod
def get_replica(
self,
healthy_replicas: List[Replica],
sess_id: str | None = None,
session_map: Dict[str, int] | None = None,
) -> Replica:
"""Select a replica from the list based on routing logic."""
pass
For RRRouter and LeastLoadedRouter, this could be None.
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.
hmm ok, I'm not sure how I feel about that longer term but that's ok for now
|
||
@pytest.mark.timeout(10) | ||
@pytest.mark.asyncio | ||
async def test_round_robin_router_distribution(): |
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.
for these router integration tests, are these not already covered in the above tests?
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.
Most functionalities are covered. But the above tests are only testing router itself. The integration tests are testing routing behaviors through a service. If you have concerns about the CI overhead, we could get ride of these except test_round_robin_router_distribution
, which is the only test for roundrobin.
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.
I removed one integration tests and 2 other unit tests due to overlapped coverage, so now just one unit test and two integration tests:
test_session_router_with_round_robin_fallback
: test different fallback router for the SessionRouter. Also tests the correctness ofLeastLoadedRouter
.test_round_robin_router_distribution
(integration): the only test case for RR logictest_session_router_assigns_and_updates_session_map_in_service
(integration): is to test whether the session_map modified in Router can get updated properly in Service class.
So I think we should keep both.
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.
sgtm
return replica | ||
|
||
|
||
class LeastLoadedRouter(Router): |
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.
nit: BalancedRouter?
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.
I think LeastConnectedRouter
would be the most canonically accurate
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.
Thanks for the suggestion!
See Allen's discussion on this in another thread.
I think
LeastConnectedRouter
would be the most canonically accurate
I agree. So let's keep it as LeastConnectedRouter
for now.
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.
Thanks @DNXie !
) | ||
|
||
|
||
class Router(ABC): |
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.
nit - I think this Router can actually just be in router.py
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.
I think we cam keep it in interface.py since that's where all the interfaces are.
return replica | ||
|
||
|
||
class LeastLoadedRouter(Router): |
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.
I think LeastConnectedRouter
would be the most canonically accurate
def get_replica( | ||
self, | ||
replicas: List["Replica"], | ||
sess_id: str | None = None, |
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.
hmm ok, I'm not sure how I feel about that longer term but that's ok for now
|
||
@pytest.mark.timeout(10) | ||
@pytest.mark.asyncio | ||
async def test_round_robin_router_distribution(): |
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.
sgtm
This PR refactors the Service routing logic into separate router classes.
Changes:
RoundRobinRouter
,LeastLoadedRouter
, andSessionRouter
.Router
interface.Service
class accordingly.SessionRouter
andLeastLoadedRouter
behavior and fallback routing.Test: