Skip to content

Commit

Permalink
Disk optimization (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmielchen authored Jan 14, 2024
1 parent 4f0b157 commit ae7f2d9
Show file tree
Hide file tree
Showing 14 changed files with 1,116 additions and 224 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[env]
LOG_LEVEL = "info"
DATA_DIR = { value = "target/data", relative = true}
LOG_LEVEL = "trace"
DATA_DIR = { value = "target/tmp/dev.bin", relative = true}
PORT = "8654"
CACHE_SIZE = "10000"
CACHE_TTL = "300"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ simple_logger = "4.3.0"

serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
postcard = { version = "1.0.8", features = ["alloc"] }

moka = { version = "0.12.2", features = ["future"] }

2 changes: 1 addition & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN cargo install --path .

FROM debian:bookworm-slim
ENV LOG_LEVEL=info
ENV DATA_DIR=/data
ENV DATA_DIR=/data/varia.bin
ENV PORT=8654
ENV CACHE_SIZE=10000
ENV CACHE_TTL=3600
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod server;
pub mod store;
pub mod setup;
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod store;
pub mod server;

pub mod setup;

#[tokio::main]
Expand Down
4 changes: 2 additions & 2 deletions src/server/engine_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Service<HttpRequest<Incoming>> for EngineService {
SerializedRespond::Ok
},
DeserializedRequest::Get(key) => {
let value = engine.get(&key).await;
let value = engine.get(key).await;

if let Err(e) = value {
let msg = format!("Failed to get value: {}", e.to_string());
Expand All @@ -88,7 +88,7 @@ impl Service<HttpRequest<Incoming>> for EngineService {
},
DeserializedRequest::Del(key) => {

if let Err(e) = engine.del(&key).await {
if let Err(e) = engine.del(key).await {
let msg = format!("Failed to delete value: {}", e.to_string());
error!("{}", msg);
return Ok(
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn setup_secondary(path: String) -> Disk {
secondary.unwrap()
}

pub fn setup_primary(size: u64, ttl: u64, tti: u64) -> Cache<String, Value> {
pub fn setup_primary(size: u64, ttl: u64, tti: u64) -> Cache<String, Option<Value>> {
Cache::builder()
.max_capacity(size)
.time_to_live(Duration::from_secs(ttl))
Expand All @@ -85,7 +85,7 @@ pub fn setup_primary(size: u64, ttl: u64, tti: u64) -> Cache<String, Value> {
.build()
}

pub fn setup_engine(secondary: Disk, primary: Cache<String, Value>) -> Engine {
pub fn setup_engine(secondary: Disk, primary: Cache<String, Option<Value>>) -> Engine {
Engine::new(secondary, primary)
}

Expand Down
Loading

0 comments on commit ae7f2d9

Please sign in to comment.