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

Process-wide channel cache for gRPC+aio #120

Merged
merged 34 commits into from
Nov 17, 2020
Merged

Conversation

justheuristic
Copy link
Member

@justheuristic justheuristic commented Nov 17, 2020

  • process-wide grpc channel/stub caching
    • implemented hivemind.utils.grpc.ChannelCache
    • extracted TimedStorage from hivemind.dht.storage to hivmind.utils.timed_storage
    • use in hivemind/client/expert.py
      • verify no performance degradation
    • use in hivemind/dht/protocol.py
      • verify no performance degradation (upd: got faster)
    • use in hivemind.client.allreduce.py
      • verify no performance degradation
  • dht.get_endpoint() to discover this peer's current public endpoint from peers
  • implement a basic synchronization check for get_dht_time()

process-wide channel caching

Currently, each time we query a remote peer with gRPC, we have to create a new channel.
In contrast, gRPC best practices recommend reusing channels for multiple rpc calls

hivemind/client/expert.py introduced channel caching, but it had a side-effect of keeping channels open forever

In this PR we implement a process-wide ChannelCache object that keeps track of open channels. The code is largely inspired by https://github.com/grpc/grpc/blob/master/src/python/grpcio/grpc/_simple_stubs.py , but with the added support for grpc.aio channels.

@justheuristic justheuristic force-pushed the dht_update_nov branch 2 times, most recently from e7ca5e9 to e9e47d1 Compare November 17, 2020 16:13
@justheuristic
Copy link
Member Author

justheuristic commented Nov 17, 2020

upd - from discussion with @mryab -
image

we decided to postpone these two to a #98 as they are not essential for ICML experiments

@justheuristic justheuristic requested a review from mryab November 17, 2020 16:16
@justheuristic justheuristic marked this pull request as ready for review November 17, 2020 16:16
@justheuristic justheuristic changed the title miscelaneous DHT updates Process-wide channel cache for gRPC+aio Nov 17, 2020
@@ -150,9 +150,7 @@ async def accumulate(self, source: Endpoint, part: torch.Tensor) -> torch.Tensor
return await self.averaged_part

def _get(self, peer: Endpoint) -> averaging_pb2_grpc.DecentralizedAveragingStub:
Copy link
Member

Choose a reason for hiding this comment

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

I believe _get is slightly overloaded here, how about _get_peer_stub?

Copy link
Member Author

Choose a reason for hiding this comment

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

its mostly a convention with DHTProtocol._get, should we rename both?

Comment on lines +4 to +7
from __future__ import annotations
import os
import threading
from typing import NamedTuple, Sequence, Tuple, Optional, Union, Any, Dict, TypeVar, Type
Copy link
Member

Choose a reason for hiding this comment

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

If we're using from __future__ import annotations, do we need to import tuple and dict from typing?

Copy link
Member Author

Choose a reason for hiding this comment

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

i agree, but i would request to keep it as is AND write a todo for #98 , ok?

Comment on lines +39 to +41
MAXIMUM_CHANNELS = os.environ.get("GRPC_PYTHON_MANAGED_CHANNEL_MAXIMUM", 4096)
EVICTION_PERIOD_SECONDS = os.environ.get("GRPC_PYTHON_MANAGED_CHANNEL_EVICTION_SECONDS", 10 * 60)
logger.debug(f"Eviction period = {EVICTION_PERIOD_SECONDS}s, max channels = {MAXIMUM_CHANNELS}")
Copy link
Member

Choose a reason for hiding this comment

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

These constants should be module-level

Copy link
Member Author

Choose a reason for hiding this comment

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

(fixed, thanks!)

Copy link
Member Author

Choose a reason for hiding this comment

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

upd - it complicates testing, added to #98

Comment on lines 47 to 49
_eviction_thread: threading.Thread
_nearest_expiration_time: DHTExpiration
_is_active: bool
Copy link
Member

Choose a reason for hiding this comment

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

These are instance attributes and are declared during init

Copy link
Member Author

Choose a reason for hiding this comment

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

(fixed)

@justheuristic justheuristic merged commit 1754792 into master Nov 17, 2020
@justheuristic justheuristic deleted the dht_update_nov branch November 17, 2020 21:40
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.

3 participants