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

CockroachDB first query huge 7 seconds delay!! #1163

Closed
tamis-laan opened this issue Jul 12, 2024 · 2 comments
Closed

CockroachDB first query huge 7 seconds delay!! #1163

tamis-laan opened this issue Jul 12, 2024 · 2 comments

Comments

@tamis-laan
Copy link

tamis-laan commented Jul 12, 2024

  • asyncpg version: 0.29.0
  • CockroachDB version: v23.1.23
  • Python version: 3.12.4
  • Platform: Linux
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : don't know?
import os
import asyncpg
import logging

# Singleton
_db = None

async def get():
    # Get singleton
    global _db

    # Return database singleton if already connected
    if _db:
        return _db

    # Log to console
    logging.info("Connecting to database")
    _db = await asyncpg.connect(
        database = os.getenv("DB_NAME","defaultdb"),
        user     = os.getenv("DB_USER", "root"),
        password = os.getenv("DB_PASS", "root"),
        host     = os.getenv("DB_HOST", "localhost"),
        port     = os.getenv("DB_PORT", "26257")
    )

    # Return database singleton
    return _db

async def main():
    from datetime import datetime

    db = await get()

    start = datetime.now()
    await db.fetch("SELECT * FROM EVENTS")
    stop = datetime.now()
    print(stop-start)
    start = datetime.now()
    await db.fetch("SELECT * FROM EVENTS")
    stop = datetime.now()
    print(stop-start)

# Entry point
if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

There is a huge 7 seconds delay running the first query. Subsequent queries are very fast.

(.venv) > python src/database2.py
0:00:06.947757
0:00:00.000738
@eltoder
Copy link
Contributor

eltoder commented Jul 12, 2024

Possibly a duplicate of #1158

@elprans
Copy link
Member

elprans commented Jul 17, 2024

Yeah, dupe of #1158. Closing.

@elprans elprans closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
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

3 participants