Skip to content
This repository was archived by the owner on Jul 11, 2021. It is now read-only.

Commit a1a8190

Browse files
committed
fix readme
1 parent b5bc6b1 commit a1a8190

File tree

1 file changed

+130
-81
lines changed

1 file changed

+130
-81
lines changed

README.md

+130-81
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ Even basic SQL is very powerful and years upon years of experience on several SQ
1212

1313
Between all the SQL implementation, the one that best fitted the need for this module is definitely SQLite, for its velocity, portability, simplicity and capability to work in memory.
1414

15-
## Usage
15+
## Getting start
1616

17-
You can get started simply downloading the git repo:
17+
You can download the `.so` directly from github following the [release link](https://github.com/RedBeardLab/rediSQL/releases)
18+
19+
With the `.so` you can start redis passing the object as argument like so:
20+
21+
```
22+
./redis-server --loadmodule librediSQL.so
23+
```
24+
25+
## Compiling and contributing
26+
27+
If you want to compile the module yourself or contribute to the project you can simply clone the repo
1828

1929
```
2030
$ git clone http://github.com/RedBeardLab/rediSQL/
@@ -32,7 +42,9 @@ Then move inside the directory and compile the module:
3242
$ cargo build --release
3343
```
3444

35-
At this point you can launch your redis instance loading the module:
45+
At this point you should have the `.so` inside the `target/release/` directory.
46+
47+
Now launch Redis with the module load will looks similarly to this:
3648

3749
```
3850
$ ~/redis-4.0-rc1/src/redis-server --loadmodule ./target/release/librediSQL.so
@@ -59,67 +71,8 @@ $ ~/redis-4.0-rc1/src/redis-server --loadmodule ./target/release/librediSQL.so
5971
6833:M 15 Dec 16:25:53.197 * The server is now ready to accept connections on port 6379
6072
```
6173

62-
## API
63-
64-
### REDISQL.SQLITE_VERSION
65-
66-
This function reply with the version of SQLite that is actually in use.
67-
68-
```
69-
127.0.0.1:6379> REDISQL.SQLITE_VERSION
70-
3.15.1
71-
```
72-
73-
### REDISQL.CREATE_DB key
74-
75-
This function will create a new SQLite database that will be bound to `key`.
76-
77-
```
78-
127.0.0.1:6379> REDISQL.CREATE_DB user
79-
OK
80-
```
81-
82-
### REDISQL.EXEC key statement
83-
84-
This command will execute the statement against the database bound to `key`.
85-
86-
```
87-
$ ./redis-cli
88-
127.0.0.1:6379> REDISQL.CREATE_DB user
89-
OK
90-
91-
$ ./redis-cli
92-
127.0.0.1:6379> REDISQL.EXEC user "CREATE TABLE user(email TEXT, password TEXT)"
93-
OK
94-
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('test@test.it','very secret')"
95-
OK
96-
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('noob@security.io', 'password')"
97-
OK
98-
127.0.0.1:6379> REDISQL.EXEC user "SELECT * FROM user;"
99-
1) 1) "test@test.it"
100-
2) "very secret"
101-
2) 1) "noob@security.io"
102-
2) "password"
103-
127.0.0.1:6379>
104-
105-
```
106-
107-
### REDISQL.DELETE_DB key
108-
109-
This function will remove the database bound to `key`, for now the database will be completely lost after this operation.
110-
111-
This function is equivalent to `DELL key` however it won't let you delete keys that are not DBs.
112-
113-
```
114-
127.0.0.1:6379> REDISQL.DELETE_DB user
115-
OK
116-
127.0.0.1:6379> REDISQL.EXEC user "SELECT * FROM user;"
117-
(error) WRONGTYPE Operation against a key holding the wrong kind of value
118-
```
119-
12074
## Walkthrough
12175

122-
12376
After starting redis with the module rediSQL it will be just the redis you learn to love:
12477

12578
```
@@ -131,7 +84,7 @@ OK
13184
"3"
13285
```
13386

134-
But you will also able to use all the API described above
87+
But you will also able to use all the API described below:
13588

13689
```
13790
127.0.0.1:6379> REDISQL.CREATE_DB DB
@@ -201,36 +154,133 @@ OK
201154
2) 1) "anana"
202155
```
203156

204-
Errors are not yet well managed as they should be.
157+
Now you can create tables, insert data on those tables, make queries, remove elements, everything.
205158

159+
## API
206160

207-
Now you can create tables, insert data on those tables, make queries, remove elements, everything.
161+
### REDISQL.CREATE_DB key
208162

209-
Finally all the above features can be applied to the default DB or to a databases bound to a specif key.
163+
This function will create a new SQLite database that will be bound to `key`.
210164

211-
## Benchmark
165+
```
166+
127.0.0.1:6379> REDISQL.CREATE_DB user
167+
OK
168+
```
212169

213-
Benchmarks are a little tricky, there are a lot of factor that may alter them, especially in this particular case.
170+
### REDISQL.EXEC key statement
214171

215-
However just to have an idea of the order of magnitude of insert per second I wrote a [little test](https://github.com/RedBeardLab/rediSQL/blob/381e3796ad31c231719380afb92352c54b244b8c/test/performance/rediSQL_bench.py).
172+
This command will execute the statement against the database bound to `key`.
216173

217-
On my machine I got 1000 insert (each one in its own transaction) in 0.6 seconds which let me claim 1000 / 0.6 => 1600 insert per second.
174+
```
175+
$ ./redis-cli
176+
127.0.0.1:6379> REDISQL.CREATE_DB user
177+
OK
218178
219-
I believe that there are A LOT of possibilities to improvements this numbers but I also thinks that they are good enough for most workload.
179+
$ ./redis-cli
180+
127.0.0.1:6379> REDISQL.EXEC user "CREATE TABLE user(email TEXT, password TEXT)"
181+
OK
182+
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('test@test.it','very secret')"
183+
OK
184+
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('noob@security.io', 'password')"
185+
OK
186+
127.0.0.1:6379> REDISQL.EXEC user "SELECT * FROM user;"
187+
1) 1) "test@test.it"
188+
2) "very secret"
189+
2) 1) "noob@security.io"
190+
2) "password"
191+
127.0.0.1:6379>
192+
193+
```
194+
195+
## Benchmarks
196+
197+
Benchmarks are always tricky and it definitely depends on your use case, however I can provide some number at least for `INSERT` operations.
198+
199+
I ran a simple benchmark where I insert a tuple of 3 integers.
200+
201+
I start establishing a baseline:
202+
203+
```
204+
$ ./redis-benchmark -e -c 50 -n 500000 -r 100000 PING
205+
====== PING ======
206+
500000 requests completed in 7.30 seconds
207+
50 parallel clients
208+
3 bytes payload
209+
keep alive: 1
210+
211+
99.76% <= 1 milliseconds
212+
100.00% <= 2 milliseconds
213+
100.00% <= 2 milliseconds
214+
68483.77 requests per second
215+
```
216+
217+
Now I ran my benchmark:
218+
219+
```
220+
$ ./redis-benchmark -e -c 50 -n 500000 -r 100000 REDISQL.EXEC A "INSERT INTO test VALUES(__rand_int__,__rand_int__,__rand_int__);"
221+
====== REDISQL.EXEC A INSERT INTO test VALUES(__rand_int__,__rand_int__,__rand_int__); ======
222+
500000 requests completed in 10.44 seconds
223+
50 parallel clients
224+
3 bytes payload
225+
keep alive: 1
226+
227+
84.19% <= 1 milliseconds
228+
99.38% <= 2 milliseconds
229+
99.92% <= 3 milliseconds
230+
99.93% <= 9 milliseconds
231+
99.94% <= 10 milliseconds
232+
99.95% <= 11 milliseconds
233+
99.95% <= 13 milliseconds
234+
99.95% <= 14 milliseconds
235+
99.96% <= 15 milliseconds
236+
99.96% <= 78 milliseconds
237+
99.96% <= 79 milliseconds
238+
99.97% <= 80 milliseconds
239+
99.97% <= 89 milliseconds
240+
99.97% <= 90 milliseconds
241+
99.98% <= 91 milliseconds
242+
99.98% <= 94 milliseconds
243+
99.98% <= 95 milliseconds
244+
99.99% <= 96 milliseconds
245+
99.99% <= 98 milliseconds
246+
99.99% <= 99 milliseconds
247+
100.00% <= 100 milliseconds
248+
100.00% <= 101 milliseconds
249+
100.00% <= 101 milliseconds
250+
47915.67 requests per second
251+
```
252+
253+
### Result
254+
255+
Overall Redis was able to manage ~70K PING per second and the module ~50K SQL inserts per seconds.
256+
257+
This is a very narrow test and if you care about performance, you should perform your own test; I would love if you could share your result.
258+
259+
Overall there are a lot of opportunity to optimize the SQL.
260+
261+
Also, keep in mind, that I am running those test in an old machine and your numbers may be different.
262+
263+
264+
## Safeness vs. Performance
265+
266+
The tradeoff between safeness and performace is always crucial in all applications.
267+
268+
Since Redis is born as am in-memory database, as default, also the RediSQL modules works with in memory databases, however you can create a standard, file backed, database.
269+
270+
Also, you can adjust all the PRAGMA settings to fit your uses case.
220271

221-
If you need something faster, please take the time to open an issues and describe your use case.
222272

223273
## RoadMap
224274

225275
We would like to move following the necessity of the community, so ideas and use cases are extremely welcome.
226276

227277
We do have already a couple of ideas:
228278

229-
1. Introducing concurrency and non-blocking queries.
279+
[x] Introducing concurrency and non-blocking queries.
230280

231-
2. Stream all the statements that modify the data, everything but `SELECT`s.
281+
[ ] Supports for prepared statements
232282

233-
3. A cache system to store the result of the more complex select.
283+
[ ] A cache system to store the result of the more complex select.
234284

235285
But please share your thoughts.
236286

@@ -261,18 +311,17 @@ However when the dimension of the dataset start to approach a terabyte you may b
261311

262312
Of course if you use SQLite as in memory database the limiting factor will be the memory of your machine.
263313

264-
## Limit of the module
265-
266-
Right now there are some limit on the module implementation, these limitation are because my lack of time.
314+
## Single thread
267315

268-
#### Single thread
316+
When you create a new database a new thread is started, all the operations on the database will be performed by only that thread.
269317

270-
Right now the module use a single thread, the good news is that the thread is a different one that the Redis thread, this means that even during long operation your redis instance will be responsive.
318+
The choice of using a single thread, in my tests, yielded overall better performaces.
271319

320+
Clearly, if the load is mainly reads, this choice will not be optimal.
272321

273322
## Alpha code
274323

275-
This is extremelly alpha code, there will be definitely some rough edges and some plain bugs.
324+
This is alpha code, there will be definitely some rough edges and some plain bugs.
276325

277326
I really appreciate if you take your time to report those bugs.
278327

0 commit comments

Comments
 (0)