-
Notifications
You must be signed in to change notification settings - Fork 115
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
Multiple connections & threads from a single process #378
Comments
Unfortunately the rust client api does not separate the |
I will do a POC per your pointers and share my findings. Thank you. |
@dowusu care to sure your findings? What worked in the end the best for you? |
I ended up with something that looks like the below; btw pub struct MemCache {
conn: Connection,
conf: PrestoSettings,
}
impl MemCache {
pub fn new(conf: PrestoSettings) -> Result<Self> {
let conn = Connection::open_in_memory()?;
info!("Creating an in-memory database.");
Ok(Self { conn, conf })
}
pub fn get_connection(&self) -> Result<Connection> {
self.conn.try_clone()
}
} Usage was along these lines let db = MemCache::new(config);
for i in 0..10 {
let conn = db.get_connection().expect("Handle the error, I've not had a single failure");
thread::spawn(move || {
// you can work with the connection object/struct
});
} I hope this helps. Thank you. |
Nice! Thanks for the reply! |
I tried wrapping
Connection
withArc
in order to use it across multiple thread only to run into an error,InnerConnection
is wrapped in aRefCell
.Per the duckdb docs, multiple reads and writes should be possible from a single process, the python lib allows that and I was wondering if there's a way to achieve this.
My current implementation involves creating a database with
Connection::open("file_name")
and subsequently calling this same function within each thread; it didn't work as I kept getting an error of the file being used by an existing process.Is there something I'm missing? my current option to use channel
mpsc
where the consumer will hold a connection to the database and do the insertion from the producers within the multiple threads.Thank you for the great work.
The text was updated successfully, but these errors were encountered: