You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As @Lorak-mmk noted in the review, runtimes are currently not shared
between `CassCluster` instances, which leads to possible many tokio
runtimes being created in the application, with possibly a lot
of threads. This commit introduces a cache for tokio runtimes, which
is encapsulated in the global `Runtimes` struct.
1. `CassCluster` now does not store a `tokio::runtime::Runtime`
directly, but rather an optional number of threads in the runtime.
2. The `Runtimes` struct is a global cache for tokio runtimes.
It allows to get a default runtime or a runtime with a specified
number of threads. Upon `cass_session_connect`, if a runtime is not
created yet, it will create a new one and cache it for future use.
The handling of the cache is fully transparent to the user of the
abstraction. `CassSession` since then holds an `Arc<Runtime>`.
3. Once all `CassSession` instances that reference a runtime are
dropped, the runtime is also dropped. This is done by storing weak
pointers to runtimes in the `Runtimes` struct.
Interesting to note: as Weak pointers keep the Arc allocation alive,
a workflow that for consecutive `i`s connects a `CassSession` with a
runtime with `i` threads and then drops it, will lead to space leaks.
This is an artificial case, though.
Remember that while the allocation will be still kept alive, the
runtime itself will not be running, as it is dropped when the last
`CassSession` referencing it is dropped.
0 commit comments