Skip to content

perf: tweak batching#3655

Merged
Flo4604 merged 1 commit intomainfrom
07-23-perf_tweak_batching
Jul 23, 2025
Merged

perf: tweak batching#3655
Flo4604 merged 1 commit intomainfrom
07-23-perf_tweak_batching

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Jul 23, 2025

What does this PR do?

Adjusts ClickHouse client configuration to optimize performance by:

  • Increasing the flush interval from 1 second to 5 seconds for all data streams
  • Reducing the number of consumers from 4 to 2 for API requests and key verification requests
  • Reducing the number of consumers from 8 to 2 for rate limit requests

These changes aim to reduce the frequency of database writes and decrease resource consumption while maintaining adequate throughput.

Fixes #(issue)

Type of change

  • Enhancement (small improvements)
  • Chore (refactoring code, technical debt, workflow improvements)

How should this be tested?

  • Monitor ClickHouse performance metrics before and after deployment to verify reduced write frequency
  • Verify that data is still being properly written to the database with the new flush interval
  • Check system resource utilization to confirm reduced CPU/memory usage from fewer consumer threads

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Summary by CodeRabbit

  • Chores
    • Updated batch processing settings to adjust flush intervals and the number of concurrent consumers, which may affect the responsiveness and throughput of certain background operations.

@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2025

⚠️ No Changeset found

Latest commit: 63bbbc5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jul 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 6:54pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 6:54pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

📝 Walkthrough

Walkthrough

The batch processing settings in the ClickHouse client were updated: the flush interval for all three batch processors was increased from 1 to 5 seconds, and the number of concurrent consumers for each processor was reduced, with the ratelimits batch seeing the largest reduction. No other logic or exported declarations were changed.

Changes

File(s) Change Summary
go/pkg/clickhouse/client.go Increased batch FlushInterval from 1s to 5s; reduced Consumers for API/key batches (4→2), ratelimits batch (8→2).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@chronark chronark marked this pull request as ready for review July 23, 2025 18:54
@vercel vercel bot temporarily deployed to Preview – engineering July 23, 2025 18:54 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard July 23, 2025 18:54 Inactive
@github-actions
Copy link
Contributor

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
go/pkg/clickhouse/client.go (1)

178-184: Shutdown only closes one processor — leaks goroutines & data.

c.keyVerifications and c.ratelimits remain open, risking lost data and goroutine leaks on shutdown.

 func (c *clickhouse) Shutdown(ctx context.Context) error {
-	c.requests.Close()
+	c.requests.Close()
+	c.keyVerifications.Close()
+	c.ratelimits.Close()
 	err := c.conn.Close()
♻️ Duplicate comments (1)
go/pkg/clickhouse/client.go (1)

123-125: Same configurability concern for key-verification batch.

If this batch backs up, API calls that rely on verification metrics may lag. Propagating the tunable approach here keeps behaviour consistent across processors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37916bc and 63bbbc5.

📒 Files selected for processing (1)
  • go/pkg/clickhouse/client.go (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: chronark
PR: unkeyed/unkey#3161
File: go/pkg/clickhouse/schema/databases/001_verifications/002_raw_key_verifications_v1.sql:31-33
Timestamp: 2025-04-22T14:40:51.459Z
Learning: The ClickHouse table schemas in the codebase mirror the production environment and cannot be modified directly in PRs without careful migration planning.
go/pkg/clickhouse/client.go (1)

Learnt from: Flo4604
PR: #3606
File: go/pkg/db/replica.go:8-11
Timestamp: 2025-07-16T15:38:53.491Z
Learning: For debugging database replica usage in go/pkg/db/replica.go, it's acceptable to mark QueryRowContext operations as "success" even though SQL errors only surface during row.Scan() calls. The timing metrics are the primary concern for debugging replica performance patterns.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: Test Packages / Test
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
go/pkg/clickhouse/client.go (1)

142-144: Largest down-scaling (8 → 2 consumers) – watch for backlog/drops.

Drop: true means overflowed events vanish silently. Rate-limit traffic often spikes; a ×4 reduction in workers plus a 5 s flush could increase drop rate.

  1. Deploy with elevated metrics:
    • queue depth / dropped events
    • flush latency
  2. Be ready to revert the consumer count if drops rise.

@graphite-app
Copy link

graphite-app bot commented Jul 23, 2025

TV gif. Timmy from Shaun the Sheep blinks and extends 2 thumbs up as a lopsided grin emerges on the side of his face. (Added via Giphy)

@graphite-app
Copy link

graphite-app bot commented Jul 23, 2025

Graphite Automations

"Notify author when CI fails" took an action on this PR • (07/23/25)

1 teammate was notified to this PR based on Andreas Thomas's automation.

"Post a GIF when PR approved" took an action on this PR • (07/23/25)

1 gif was posted to this PR based on Andreas Thomas's automation.

@Flo4604 Flo4604 added this pull request to the merge queue Jul 23, 2025
Merged via the queue into main with commit 3cb2cbc Jul 23, 2025
31 of 34 checks passed
@Flo4604 Flo4604 deleted the 07-23-perf_tweak_batching branch July 23, 2025 20:06
@coderabbitai coderabbitai bot mentioned this pull request Sep 18, 2025
18 tasks
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

Successfully merging this pull request may close these issues.

2 participants