Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iprep
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ai3
tools
iprep
Commits
7ca90739
Commit
7ca90739
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add multi-threaded database benchmarks
parent
05de320f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
db/db_test.go
+41
-22
41 additions, 22 deletions
db/db_test.go
with
41 additions
and
22 deletions
db/db_test.go
+
41
−
22
View file @
7ca90739
...
...
@@ -6,6 +6,7 @@ import (
"math/rand"
"os"
"os/exec"
"sync"
"testing"
"time"
...
...
@@ -163,7 +164,7 @@ func BenchmarkWrite_Sqlite(b *testing.B) {
runWriteBench
(
b
,
"sqlite"
)
}
func
runReadBenchmark
(
b
*
testing
.
B
,
driver
string
,
eventsPerIP
int
)
{
func
runReadBenchmark
(
b
*
testing
.
B
,
driver
string
,
eventsPerIP
int
,
threadCounts
[]
int
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
""
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
...
...
@@ -200,40 +201,58 @@ func runReadBenchmark(b *testing.B, driver string, eventsPerIP int) {
}
deadline
:=
time
.
Now
()
.
Add
(
-
1
*
time
.
Hour
)
b
.
ResetTimer
()
ipCount
:=
0
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
refIP
:=
refIPs
[
ipCount
]
ipCount
++
if
ipCount
>=
len
(
refIPs
)
{
ipCount
=
0
}
m
,
err
:=
db
.
ScanIP
(
deadline
,
refIP
)
if
err
!=
nil
{
b
.
Fatalf
(
"ScanIP(%d): %v"
,
i
,
err
)
}
if
len
(
m
)
==
0
{
b
.
Fatalf
(
"ScanIP(%d): returned empty result"
,
i
)
}
if
len
(
m
[
"test"
])
<
1
{
b
.
Fatalf
(
"ScanIP(%d): returned bad results: %v"
,
i
,
m
)
fn
:=
func
(
b
*
testing
.
B
,
off
int
)
{
ipCount
:=
(
off
*
13
)
%
len
(
refIPs
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
refIP
:=
refIPs
[
ipCount
]
ipCount
++
if
ipCount
>=
len
(
refIPs
)
{
ipCount
=
0
}
m
,
err
:=
db
.
ScanIP
(
deadline
,
refIP
)
if
err
!=
nil
{
b
.
Fatalf
(
"ScanIP(%d): %v"
,
i
,
err
)
}
if
len
(
m
)
==
0
{
b
.
Fatalf
(
"ScanIP(%d): returned empty result"
,
i
)
}
if
len
(
m
[
"test"
])
<
1
{
b
.
Fatalf
(
"ScanIP(%d): returned bad results: %v"
,
i
,
m
)
}
}
}
// Now run separate benchmarks for each of the threadCounts values.
for
_
,
numThreads
:=
range
threadCounts
{
b
.
Run
(
fmt
.
Sprintf
(
"threads:%d"
,
numThreads
),
func
(
b
*
testing
.
B
)
{
var
wg
sync
.
WaitGroup
for
i
:=
0
;
i
<
numThreads
;
i
++
{
wg
.
Add
(
1
)
go
func
(
i
int
)
{
fn
(
b
,
i
)
wg
.
Done
()
}(
i
)
}
wg
.
Wait
()
})
}
}
var
threadTests
=
[]
int
{
1
,
5
,
50
}
func
BenchmarkRead_LevelDB_SmallAggregate
(
b
*
testing
.
B
)
{
runReadBenchmark
(
b
,
"leveldb"
,
5
)
runReadBenchmark
(
b
,
"leveldb"
,
5
,
threadTests
)
}
func
BenchmarkRead_LevelDB_LargeAggregate
(
b
*
testing
.
B
)
{
runReadBenchmark
(
b
,
"leveldb"
,
1000
)
runReadBenchmark
(
b
,
"leveldb"
,
1000
,
threadTests
)
}
func
BenchmarkRead_Sqlite_SmallAggregate
(
b
*
testing
.
B
)
{
runReadBenchmark
(
b
,
"sqlite"
,
5
)
runReadBenchmark
(
b
,
"sqlite"
,
5
,
threadTests
)
}
func
BenchmarkRead_Sqlite_LargeAggregate
(
b
*
testing
.
B
)
{
runReadBenchmark
(
b
,
"sqlite"
,
1000
)
runReadBenchmark
(
b
,
"sqlite"
,
1000
,
threadTests
)
}
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