Skip to content

Commit

Permalink
850 inserts per second -> 1500 inserts per second
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtreece committed Jan 20, 2020
1 parent 5d92551 commit f66340d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ $ 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
wrk -t10 -c100 -d 30s -s bench/post.lua http://localhost:8080/api/v1/streams/bench/data
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
Expand Down
22 changes: 16 additions & 6 deletions src/db/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -93,13 +94,22 @@ pub fn list_data(conn: Connection, key: String) -> Result<Vec<Data>, Error> {
Ok(results)
}

pub fn insert_data(conn: Connection, key: String, data: Map<String, Value>) -> Result<i64, Error> {
conn.execute("INSERT OR IGNORE INTO streams (key) VALUES (?)", &[&key])?;
pub fn insert_data(
mut conn: Connection,
key: String,
data: Map<String, Value>,
) -> 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(())
}

0 comments on commit f66340d

Please sign in to comment.