-
I've been experimenting with Rocket and different SQLite crates and it looks like there are no good ways to use SQLite in async context. SQLite doesn't offer an async API and existing attempts to create async wrappers come with severe performance hits and other issues. What should probably work fine for SQLite is a thread pool. It allows concurrent reads and it should scale fine, as long as each read has it's own connection. The problem is, this approach doesn't seem to benefit from async runtime and I don't see any sensible ways of utilizing it. What would be the implications of treating Rocket as a traditional synchronous web framework? By that I mean calling strictly sync code from async handlers. The number of worker treads is configurable, so I can start Rocket with a lot of worker threads and give each thread a database connection. Would it be any worse than using synchronous web framework with the same number of working threads? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
This would be awful for performance. The runtime (tokio) expects async tasks to return quickly. There are ways to execute blocking code in an async-safe way, such as However, I would recommend taking a look at |
Beta Was this translation helpful? Give feedback.
-
The best answer I can come up with is "It will be fine, until maybe it isn't". If (edited to add:) A different angle on this: one of the main benefits of going from sync to async is that the amount of in-flight I/O (disk, network) is no longer coupled 1:1 to OS-level threads. This means that operations that don't need I/O are not impeded, and that you need much, much fewer OS-level threads and context switches to accomplish roughly the same amount of work. Yes, there is some degree of overhead to using an async runtime, but in many applications this overhead is more than made up for by being able to handle more than |
Beta Was this translation helpful? Give feedback.
The best answer I can come up with is "It will be fine, until maybe it isn't". If
active_db_operations
is always less thanworker_threads
, I would not expect too many problems. As soon as you have more active database operations than the number of worker threads, you will start to see performance …