googleapis / googleapis/google-cloud-python

Re-using a session pool on connect() when using python-spanner with sqlalchemy

Đang mở
#15,674 3 bình luận 0 reaction 1 người được giao Được @olavloite nhận Xem trên GitHub
api: spanner priority: p3 type: feature request
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

**Is your feature request related to a problem? Please describe.**
When using SQL Alchemy with python-spanner-sqlalchemy, I've noticed that we're running `.bind()`, instantiating the `database` object and executing `BatchCreateSessions` for every single `connect()` call, which adds quite a bit of additional overhead before the query even executes. Main overhead that I saw was `BatchCreateSessions` when using a `PingingPool`.

**Describe the solution you'd like**
Would like the ability to pass in an existing `database` object (or have it be idempotent/detect that there's already a pool) so that the same pool and its pre-created sessions can be re-used for every SQL alchemy connection checkout, similar to how using the raw spanner client works.

**Describe alternatives you've considered**
I've tried passing a pool to the connect(), but it still recreates the sessions.

## Attempt 1
Draft PR: https://github.com/googleapis/python-spanner/pull/1493/changes

While this PR works for my specific use case (SQL Alchemy x python-spanner-sqlalchemy + PingingPool), I am not clear of the implications of allowing the re-use of the database object. Would appreciate any guidance here

PR contains a benchmarking script that tests a 7 combinations (raw spanner client, mix of values for QueuePool/StaticPool x Spanner's PingingPool):

Image

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.