Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dpcollins-google
Copy link
Collaborator

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@dpcollins-google dpcollins-google requested review from a team as code owners August 15, 2021 13:52
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 15, 2021
@product-auto-label product-auto-label bot added the api: pubsublite Issues related to the googleapis/python-pubsublite API. label Aug 15, 2021

class ClientMultiplexer(Generic[_Key, _Client]):
_OpenedClientFactory = Callable[[], _Client]
_OpenedClientFactory = Callable[[_Key], _Client]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a lot of "self" time in get_or_create callers from constructing the factory to pass in. This is in the publish hot path, hence this change

_closer: _ClientCloser
_lock: asyncio.Lock
_live_clients: Dict[_Key, _Client]
_live_clients: Dict[_Key, Awaitable[_Client]]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a lot of time in acquiring the lock in the publish hotpath- this change makes the lock not necessary


_multiplexer: ClientMultiplexer[SubscriptionPath, StreamingPullFuture]
_lock: Lock
_live_clients: Set[StreamingPullFuture]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously, the subscriber enforced that there was only one open subscription stream per-subscription per-client, but there's actually no need for this.


def should_flush(self) -> bool:
return self._tester.test(item.request for item in self._requests)
def size(self) -> BatchSize:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of the CPU in the publish path was in should_flush calls, which had to construct an iterable and iterate through every time.

element_count=1, byte_count=PubSubMessage.pb(request).ByteSize()
)

def _should_flush(self) -> bool:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you'll note on the left... batching settings were previously ignored

@dpcollins-google dpcollins-google added the automerge Merge the pull request once unit tests and other checks pass. label Aug 16, 2021
@gcf-merge-on-green gcf-merge-on-green bot merged commit 358a1d8 into master Aug 16, 2021
@gcf-merge-on-green gcf-merge-on-green bot deleted the optimize-python branch August 16, 2021 14:16
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsublite Issues related to the googleapis/python-pubsublite API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants