diff --git a/Makefile b/Makefile index fb7ff4b..f015354 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,6 @@ clean: @rm dlphn-$(VERSION)-*.tar.gz bench: - wrk -t20 -c200 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/bench/data + wrk -t10 -c100 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/bench/data .PHONY: bench ui ui-client ui-deps release all diff --git a/README.md b/README.md index e438a6a..da7029b 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,9 @@ $ dlphn ## benchmarks -### post +### logging data -~850 inserts per second via the REST API. results from 2017 intel nuc 3.5GHz i7-7567U kaby lake: +~1500 inserts per second via the REST API. results from 2017 intel nuc 3.5GHz i7-7567U kaby lake: ```sh $ make bench @@ -69,13 +69,13 @@ wrk -t10 -c100 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/ben Running 30s test @ http://localhost:8080/api/v1/streams/bench/data 10 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev - Latency 128.96ms 140.03ms 1.96s 96.39% - Req/Sec 87.02 11.70 120.00 62.27% - 26085 requests in 30.10s, 1.87MB read - Socket errors: connect 0, read 0, write 0, timeout 35 + Latency 84.69ms 147.65ms 2.00s 96.57% + Req/Sec 153.37 25.66 262.00 70.56% + 45957 requests in 30.10s, 3.29MB read + Socket errors: connect 0, read 0, write 0, timeout 41 Non-2xx or 3xx responses: 1 -Requests/sec: 866.51 -Transfer/sec: 63.47KB +Requests/sec: 1526.97 +Transfer/sec: 111.84KB ``` ## license diff --git a/src/db/sqlite.rs b/src/db/sqlite.rs index 6679034..ad7fcca 100644 --- a/src/db/sqlite.rs +++ b/src/db/sqlite.rs @@ -32,7 +32,8 @@ pub fn create_table(conn: Connection) -> Result<(), Error> { created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY(stream_id) REFERENCES streams(id) - );", + ); + PRAGMA synchronous = OFF;", )?; Ok(()) @@ -93,13 +94,22 @@ pub fn list_data(conn: Connection, key: String) -> Result, Error> { Ok(results) } -pub fn insert_data(conn: Connection, key: String, data: Map) -> Result { - conn.execute("INSERT OR IGNORE INTO streams (key) VALUES (?)", &[&key])?; +pub fn insert_data( + mut conn: Connection, + key: String, + data: Map, +) -> Result<(), Error> { + let tx = conn.transaction()?; - let mut stmt = conn.prepare( + tx.execute("INSERT OR IGNORE INTO streams (key) VALUES (?)", &[&key])?; + + tx.execute( "INSERT INTO data (payload, stream_id) - VALUES (?, (SELECT streams.id FROM streams WHERE streams.key = ?))", + SELECT ?, streams.id FROM streams WHERE streams.key = ?", + &[&Value::Object(data) as &dyn ToSql, &key], )?; - Ok(stmt.insert(&[&Value::Object(data) as &dyn ToSql, &key])?) + tx.commit()?; + + Ok(()) }