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

FixedSizePool.bind unconditionally requests for the same session count on every loop iteration, hence could end up creating much more sessions than necessary; should decrement them per call #1226

Open
odeke-em opened this issue Nov 6, 2024 · 0 comments
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner API.

Comments

@odeke-em
Copy link
Contributor

odeke-em commented Nov 6, 2024

Found while I was writing tests for PR #1207 that this code in each iteration requests for the original number of sessions in every loop iteration

while not self._sessions.full():
resp = api.batch_create_sessions(
request=request,
metadata=metadata,
)
for session_pb in resp.session:
session = self._new_session()
session._session_id = session_pb.name.split("/")[-1]
self._sessions.put(session)

and the basic tests inside tests/unit/test_pool.py when ran, the loop runs twice but each time the count is kept the exact same per
resp = api.batch_create_sessions(
request=request,
metadata=metadata,
)

You can add prints and you'll see that the loop runs twice but each time 2 sessions are returned but yet 4 sessions were requested

Suggestion

The correct remedy for this is that per iteration, the current size of the filled in queue must be considered in relation to filling it up request.session_count = requested_session_count - self._sessions.qsize()

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API.
Projects
None yet
Development

No branches or pull requests

2 participants