Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
a05ecf4a
Commit
a05ecf4a
authored
9 years ago
by
Manish R Jain
Browse files
Options
Downloads
Patches
Plain Diff
RocksDB integration done!
parent
947b1c2d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
store/README.md
+35
-0
35 additions, 0 deletions
store/README.md
store/store.go
+21
-13
21 additions, 13 deletions
store/store.go
store/store_test.go
+70
-0
70 additions, 0 deletions
store/store_test.go
with
126 additions
and
13 deletions
store/README.md
0 → 100644
+
35
−
0
View file @
a05ecf4a
Results of benchmarking
------------------------
Using RocksDB
So, reading times are on the order of single unit microseconds, while writing
times with
`Sync`
set to true are ~30 milliseconds.
```
$ go test -run BenchmarkSet -v -bench .
PASS
BenchmarkGet_valsize100-6 500000 2850 ns/op
--- BENCH: BenchmarkGet_valsize100-6
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
BenchmarkGet_valsize1000-6 500000 3565 ns/op
--- BENCH: BenchmarkGet_valsize1000-6
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
BenchmarkGet_valsize10000-6 200000 8541 ns/op
--- BENCH: BenchmarkGet_valsize10000-6
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
store_test.go:85: Wrote 100 keys.
BenchmarkSet_valsize100-6 50 32932578 ns/op
BenchmarkSet_valsize1000-6 50 28066678 ns/op
BenchmarkSet_valsize10000-6 50 28736228 ns/op
ok github.com/dgraph-io/dgraph/store 48.393s
```
This diff is collapsed.
Click to expand it.
store/store.go
+
21
−
13
View file @
a05ecf4a
...
...
@@ -17,21 +17,29 @@
package
store
import
(
"github.com/dgraph-io/dgraph/store/rocksdb"
"github.com/dgraph-io/dgraph/x"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
)
var
log
=
x
.
Log
(
"store"
)
type
Store
struct
{
db
*
leveldb
.
DB
opt
*
opt
.
Options
db
*
rocksdb
.
DB
opt
*
rocksdb
.
Options
ropt
*
rocksdb
.
ReadOptions
wopt
*
rocksdb
.
WriteOptions
}
func
(
s
*
Store
)
Init
(
filepath
string
)
{
s
.
opt
=
rocksdb
.
NewOptions
()
s
.
opt
.
SetCreateIfMissing
(
true
)
s
.
ropt
=
rocksdb
.
NewReadOptions
()
s
.
wopt
=
rocksdb
.
NewWriteOptions
()
s
.
wopt
.
SetSync
(
true
)
var
err
error
s
.
db
,
err
=
level
db
.
Open
File
(
filepath
,
s
.
opt
)
s
.
db
,
err
=
rocks
db
.
Open
(
filepath
,
s
.
opt
)
if
err
!=
nil
{
x
.
Err
(
log
,
err
)
.
WithField
(
"filepath"
,
filepath
)
.
Fatal
(
"While opening store"
)
...
...
@@ -39,24 +47,24 @@ func (s *Store) Init(filepath string) {
}
}
/*
func (s *Store) IsNew(id uint64) bool {
return false
}
*/
func
(
s
*
Store
)
Get
(
k
[]
byte
)
(
val
[]
byte
,
rerr
error
)
{
return
s
.
db
.
Get
(
k
,
nil
)
func
(
s
*
Store
)
Get
(
k
ey
[]
byte
)
(
val
[]
byte
,
rerr
error
)
{
return
s
.
db
.
Get
(
s
.
ropt
,
key
)
}
func
(
s
*
Store
)
SetOne
(
k
[]
byte
,
val
[]
byte
)
error
{
wb
:=
new
(
leveldb
.
Batch
)
wb
.
Put
(
k
,
val
)
return
s
.
db
.
Write
(
wb
,
nil
)
return
s
.
db
.
Put
(
s
.
wopt
,
k
,
val
)
}
func
(
s
*
Store
)
Delete
(
k
[]
byte
)
error
{
return
s
.
db
.
Delete
(
k
,
nil
)
return
s
.
db
.
Delete
(
s
.
wopt
,
k
)
}
func
(
s
*
Store
)
Close
()
error
{
return
s
.
db
.
Close
()
func
(
s
*
Store
)
Close
()
{
s
.
db
.
Close
()
}
This diff is collapsed.
Click to expand it.
store/store_test.go
+
70
−
0
View file @
a05ecf4a
...
...
@@ -17,7 +17,9 @@
package
store
import
(
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
)
...
...
@@ -58,3 +60,71 @@ func TestGet(t *testing.T) {
t
.
Errorf
(
"Expected 'the one'. Found: %s"
,
string
(
val
))
}
}
func
benchmarkGet
(
valSize
int
,
b
*
testing
.
B
)
{
path
,
err
:=
ioutil
.
TempDir
(
""
,
"storetest_"
)
if
err
!=
nil
{
b
.
Error
(
err
)
b
.
Fail
()
return
}
defer
os
.
RemoveAll
(
path
)
var
s
Store
s
.
Init
(
path
)
buf
:=
make
([]
byte
,
valSize
)
nkeys
:=
100
for
i
:=
0
;
i
<
nkeys
;
i
++
{
key
:=
[]
byte
(
fmt
.
Sprintf
(
"key_%d"
,
i
))
if
err
:=
s
.
SetOne
(
key
,
buf
);
err
!=
nil
{
b
.
Error
(
err
)
return
}
}
b
.
Logf
(
"Wrote %d keys."
,
nkeys
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
k
:=
rand
.
Int
()
%
nkeys
key
:=
[]
byte
(
fmt
.
Sprintf
(
"key_%d"
,
k
))
val
,
err
:=
s
.
Get
(
key
)
if
err
!=
nil
{
b
.
Error
(
err
)
}
if
len
(
val
)
!=
valSize
{
b
.
Errorf
(
"Value size expected: %d. Found: %d"
,
valSize
,
len
(
val
))
}
}
}
func
BenchmarkGet_valsize100
(
b
*
testing
.
B
)
{
benchmarkGet
(
100
,
b
)
}
func
BenchmarkGet_valsize1000
(
b
*
testing
.
B
)
{
benchmarkGet
(
1000
,
b
)
}
func
BenchmarkGet_valsize10000
(
b
*
testing
.
B
)
{
benchmarkGet
(
10000
,
b
)
}
func
benchmarkSet
(
valSize
int
,
b
*
testing
.
B
)
{
path
,
err
:=
ioutil
.
TempDir
(
""
,
"storetest_"
)
if
err
!=
nil
{
b
.
Error
(
err
)
b
.
Fail
()
return
}
defer
os
.
RemoveAll
(
path
)
var
s
Store
s
.
Init
(
path
)
buf
:=
make
([]
byte
,
valSize
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
key
:=
[]
byte
(
fmt
.
Sprintf
(
"key_%d"
,
i
))
if
err
:=
s
.
SetOne
(
key
,
buf
);
err
!=
nil
{
b
.
Error
(
err
)
return
}
}
}
func
BenchmarkSet_valsize100
(
b
*
testing
.
B
)
{
benchmarkSet
(
100
,
b
)
}
func
BenchmarkSet_valsize1000
(
b
*
testing
.
B
)
{
benchmarkSet
(
1000
,
b
)
}
func
BenchmarkSet_valsize10000
(
b
*
testing
.
B
)
{
benchmarkSet
(
10000
,
b
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment