Skip to content

feat: add sr_clone() for shared-runtime independent sessions#14

Open
Adamkaram wants to merge 1 commit intosurrealdb:mainfrom
Adamkaram:main
Open

feat: add sr_clone() for shared-runtime independent sessions#14
Adamkaram wants to merge 1 commit intosurrealdb:mainfrom
Adamkaram:main

Conversation

@Adamkaram
Copy link

Add sr_clone() function that creates an independent Surreal handle sharing the same underlying database engine as the original connection. Uses Arc to share the Tokio runtime across all clones — zero memory overhead per clone.

This enables multiple concurrent sessions on a single embedded (surrealkv://) connection without file locking issues. Each clone has its own namespace/database state set via sr_use_ns/sr_use_db.

Changes:

  • Change Surreal.rt from Runtime to Arc
  • Add sr_clone() C FFI function with full safety docs
  • Update surrealdb.h with sr_clone declaration
  • Clean up enum/comment formatting in surrealdb.h

Use case: Multi-tenant WhatsApp service with thousands of instances sharing one surrealkv file. Each instance gets an sr_clone() with independent NS/DB state. Benchmark: 17,111 q/s (20K concurrent queries across 10 clones) vs 7,577 q/s shared connection.

Add sr_clone() function that creates an independent Surreal handle sharing
the same underlying database engine as the original connection. Uses
Arc<Runtime> to share the Tokio runtime across all clones — zero memory
overhead per clone.

This enables multiple concurrent sessions on a single embedded
(surrealkv://) connection without file locking issues. Each clone
has its own namespace/database state set via sr_use_ns/sr_use_db.

Changes:
- Change Surreal.rt from Runtime to Arc<Runtime>
- Add sr_clone() C FFI function with full safety docs
- Update surrealdb.h with sr_clone declaration
- Clean up enum/comment formatting in surrealdb.h

Use case: Multi-tenant WhatsApp service with thousands of instances
sharing one surrealkv file. Each instance gets an sr_clone() with
independent NS/DB state. Benchmark: 17,111 q/s (20K concurrent
queries across 10 clones) vs 7,577 q/s shared connection.
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, reopen this pull request to trigger a review.

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.

1 participant