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

perf: Speedup empty db.{commit|rollback} by ~2x #28885

Closed
wants to merge 1 commit into from

Conversation

ankush
Copy link
Member

@ankush ankush commented Dec 23, 2024

Ref:

Both Postgres and MariaDB support re-creating a new transaction using single command, so, no need to send 2 separate commands 😄

Benchmark before db-api commit manually chaining
bench_database_bench_empty_transaction_cycling 237 us 163 us: 1.46x faster 118 us: 2.01x faster

Note: 2x obviously won't hold when there's something to flush to disk because it will require an fsync. This should still help in the vast majority of read-only requests.

Side effects:

  • None known

1. No more "logging" of these queries, can be solved by just fake logging.
2. Things that don't start transaction will now also won't rollback.
So ping might not even connect to DB.

Note: previous impl used conn.commit() feature of DB-API 2.0 but they don't allow chaining so in the end they are less efficient than a single query that can do both.

closes frappe/caffeine#28

@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Dec 23, 2024
@ankush ankush removed the add-test-cases Add test case to validate fix or enhancement label Dec 23, 2024
@ankush ankush marked this pull request as ready for review December 23, 2024 14:00
@ankush ankush changed the title perf: Speedup db.{commit|rollback|begin} by ~1.4x perf: Speedup db.{commit|rollback} by ~2x Dec 23, 2024
@ankush ankush force-pushed the perf/db_transactions branch from 13c9345 to 9c04f81 Compare December 23, 2024 14:25
@ankush ankush enabled auto-merge (squash) December 23, 2024 14:27
@ankush ankush disabled auto-merge December 23, 2024 14:28
@ankush ankush changed the title perf: Speedup db.{commit|rollback} by ~2x perf: Speedup empty db.{commit|rollback} by ~2x Dec 23, 2024
@ankush ankush marked this pull request as draft December 23, 2024 14:35
@ankush
Copy link
Member Author

ankush commented Dec 23, 2024

err...

  • most test failures in mariadb are because they are chaining a read only transaction
  • postgres failure is because it's strict about existence of a transaction to "chain".

@ankush ankush closed this Dec 24, 2024
@ankush
Copy link
Member Author

ankush commented Dec 24, 2024

One PR at a time, will reopen when I am done with others.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use commands instead of queries for transaction management
1 participant