Skip to content

Commit f66340d

Browse files
committed
850 inserts per second -> 1500 inserts per second
1 parent 5d92551 commit f66340d

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ clean:
4141
@rm dlphn-$(VERSION)-*.tar.gz
4242

4343
bench:
44-
wrk -t20 -c200 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/bench/data
44+
wrk -t10 -c100 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/bench/data
4545

4646
.PHONY: bench ui ui-client ui-deps release all

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ $ dlphn
5959

6060
## benchmarks
6161

62-
### post
62+
### logging data
6363

64-
~850 inserts per second via the REST API. results from 2017 intel nuc 3.5GHz i7-7567U kaby lake:
64+
~1500 inserts per second via the REST API. results from 2017 intel nuc 3.5GHz i7-7567U kaby lake:
6565

6666
```sh
6767
$ make bench
6868
wrk -t10 -c100 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/bench/data
6969
Running 30s test @ http://localhost:8080/api/v1/streams/bench/data
7070
10 threads and 100 connections
7171
Thread Stats Avg Stdev Max +/- Stdev
72-
Latency 128.96ms 140.03ms 1.96s 96.39%
73-
Req/Sec 87.02 11.70 120.00 62.27%
74-
26085 requests in 30.10s, 1.87MB read
75-
Socket errors: connect 0, read 0, write 0, timeout 35
72+
Latency 84.69ms 147.65ms 2.00s 96.57%
73+
Req/Sec 153.37 25.66 262.00 70.56%
74+
45957 requests in 30.10s, 3.29MB read
75+
Socket errors: connect 0, read 0, write 0, timeout 41
7676
Non-2xx or 3xx responses: 1
77-
Requests/sec: 866.51
78-
Transfer/sec: 63.47KB
77+
Requests/sec: 1526.97
78+
Transfer/sec: 111.84KB
7979
```
8080

8181
## license

src/db/sqlite.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ pub fn create_table(conn: Connection) -> Result<(), Error> {
3232
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
3333
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
3434
FOREIGN KEY(stream_id) REFERENCES streams(id)
35-
);",
35+
);
36+
PRAGMA synchronous = OFF;",
3637
)?;
3738

3839
Ok(())
@@ -93,13 +94,22 @@ pub fn list_data(conn: Connection, key: String) -> Result<Vec<Data>, Error> {
9394
Ok(results)
9495
}
9596

96-
pub fn insert_data(conn: Connection, key: String, data: Map<String, Value>) -> Result<i64, Error> {
97-
conn.execute("INSERT OR IGNORE INTO streams (key) VALUES (?)", &[&key])?;
97+
pub fn insert_data(
98+
mut conn: Connection,
99+
key: String,
100+
data: Map<String, Value>,
101+
) -> Result<(), Error> {
102+
let tx = conn.transaction()?;
98103

99-
let mut stmt = conn.prepare(
104+
tx.execute("INSERT OR IGNORE INTO streams (key) VALUES (?)", &[&key])?;
105+
106+
tx.execute(
100107
"INSERT INTO data (payload, stream_id)
101-
VALUES (?, (SELECT streams.id FROM streams WHERE streams.key = ?))",
108+
SELECT ?, streams.id FROM streams WHERE streams.key = ?",
109+
&[&Value::Object(data) as &dyn ToSql, &key],
102110
)?;
103111

104-
Ok(stmt.insert(&[&Value::Object(data) as &dyn ToSql, &key])?)
112+
tx.commit()?;
113+
114+
Ok(())
105115
}

0 commit comments

Comments
 (0)