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

Caching disabled in sqlalchemy queries #589

Open
mekanix opened this issue Apr 9, 2024 · 1 comment
Open

Caching disabled in sqlalchemy queries #589

mekanix opened this issue Apr 9, 2024 · 1 comment

Comments

@mekanix
Copy link

mekanix commented Apr 9, 2024

There is a significant regression in speed and it's probably due to cache not being used. In ormar PR switching to SQLAlchemy2 there is a noticeable degradation in speed, and the recommendation was to check SQLAlchemy's caching. I came up with this to test for caching being disabled

env TEST_DATABASE_URLS="sqlite+aiosqlite:////tmp/db.sqlite" pytest -s tests/test_databases.py::test_queries
================================================================================================================================================= test session starts ==================================================================================================================================================
platform freebsd15 -- Python 3.9.18, pytest-7.4.4, pluggy-1.4.0
codspeed: 2.2.1 (callgraph: not supported)
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /usr/home/meka/repos/databases
plugins: benchmark-4.0.0, cov-4.1.0, asyncio-0.21.1, anyio-4.3.0, codspeed-2.2.1, Faker-24.7.1
asyncio: mode=strict
collected 1 item

tests/test_databases.py 2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("notes")
2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("articles")
2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("events")
2024-04-10 01:00:45,045 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("daily_schedule")
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("tshirt_size")
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info("tshirt_size")
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("session")
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info("session")
2024-04-10 01:00:45,046 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("custom_date")
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info("custom_date")
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("prices")
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info("prices")
2024-04-10 01:00:45,047 INFO sqlalchemy.engine.Engine [raw sql] ()
2024-04-10 01:00:45,048 INFO sqlalchemy.engine.Engine
CREATE TABLE tshirt_size (
	id INTEGER NOT NULL,
	size VARCHAR(6),
	color VARCHAR(6),
	PRIMARY KEY (id)
)


2024-04-10 01:00:45,048 INFO sqlalchemy.engine.Engine [no key 0.00008s] ()
2024-04-10 01:00:45,055 INFO sqlalchemy.engine.Engine
CREATE TABLE session (
	id INTEGER NOT NULL,
	data JSON,
	PRIMARY KEY (id)
)


2024-04-10 01:00:45,055 INFO sqlalchemy.engine.Engine [no key 0.00014s] ()
2024-04-10 01:00:45,062 INFO sqlalchemy.engine.Engine
CREATE TABLE custom_date (
	id INTEGER NOT NULL,
	title VARCHAR(100),
	published INTEGER,
	PRIMARY KEY (id)
)


2024-04-10 01:00:45,062 INFO sqlalchemy.engine.Engine [no key 0.00012s] ()
2024-04-10 01:00:45,068 INFO sqlalchemy.engine.Engine
CREATE TABLE prices (
	id INTEGER NOT NULL,
	price NUMERIC(30, 20),
	PRIMARY KEY (id)
)


2024-04-10 01:00:45,068 INFO sqlalchemy.engine.Engine [no key 0.00010s] ()
2024-04-10 01:00:45,074 INFO sqlalchemy.engine.Engine COMMIT

The no key part indicates that the caching is disabled, as per official docs. I still don't know where that no key comes from, but I do hope you can help me narrow it down.

@zanieb
Copy link
Contributor

zanieb commented Apr 10, 2024

Thanks for the report!

cc @tarsil

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

No branches or pull requests

2 participants