Talent Plan, an open source training program initiated by PingCAPcourse, this project is "TP 201: Practical Networked Applications in Rust", implements a Key-Value Store in Rust.
- Using BufReaderWithPos make performance a little bit worse, maybe file::seek is efficient enough, meantime if-branchs are extra price?
- KvStore::index_map would be used both by readers and the writer(singleton), RwLock would be a little bit inefficient(writer is locked during index_map is writting-locked for updating), lock-free map is prefered. Using
DashMap
now. - Possible optimization:
engine
is cloned for each incoming connection, it leads to createReaderMap
for every request, which is not necessarily, considerating usingsyncpool
.- before optimization, clones engine for each connection:
for stream in listener.incoming() { let engine = self.engine.clone(); self.pool.spawn(move || { serve(engine, stream); // ... }) }
- draft the optimization, replace
KvsEngine::clone()
withArc<SyncPool>::clone()
, 25% performance improved in thread-pool-size=1, no change in other size, interesting...
pub struct KvsServer<E: KvsEngine, P: ThreadPool> { // ... other fields engine_pool: Arc<SyncPool<E>>, } for stream in listener.incoming() { let engine_pool = self.engine_pool.clone(); self.pool.spawn(move || { serve(engine_pool, stream); // ... }) }