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
940766a6
Commit
940766a6
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Make the db write tests a bit faster
parent
c3a78a7e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
db/db_test.go
+7
-3
7 additions, 3 deletions
db/db_test.go
with
7 additions
and
3 deletions
db/db_test.go
+
7
−
3
View file @
940766a6
...
@@ -15,7 +15,11 @@ import (
...
@@ -15,7 +15,11 @@ import (
ippb
"git.autistici.org/ai3/tools/iprep/proto"
ippb
"git.autistici.org/ai3/tools/iprep/proto"
)
)
const
manyEvents
=
500000
const
(
// How many events to fill up the db, test/bench cases.
manyEventsTest
=
100000
manyEventsBench
=
1000000
)
func
randomIP
()
string
{
func
randomIP
()
string
{
return
fmt
.
Sprintf
(
"%d.%d.%d.%d"
,
1
+
rand
.
Intn
(
253
),
1
+
rand
.
Intn
(
253
),
1
+
rand
.
Intn
(
253
),
1
+
rand
.
Intn
(
253
))
return
fmt
.
Sprintf
(
"%d.%d.%d.%d"
,
1
+
rand
.
Intn
(
253
),
1
+
rand
.
Intn
(
253
),
1
+
rand
.
Intn
(
253
),
1
+
rand
.
Intn
(
253
))
...
@@ -68,7 +72,7 @@ func runRWTest(t *testing.T, driver string) {
...
@@ -68,7 +72,7 @@ func runRWTest(t *testing.T, driver string) {
defer
db
.
Close
()
defer
db
.
Close
()
// Write n elements.
// Write n elements.
n
:=
manyEvents
n
:=
manyEvents
Test
events
:=
randomEvents
(
n
)
events
:=
randomEvents
(
n
)
if
err
:=
db
.
AddAggregate
(
events
);
err
!=
nil
{
if
err
:=
db
.
AddAggregate
(
events
);
err
!=
nil
{
t
.
Fatalf
(
"AddEvents: %v"
,
err
)
t
.
Fatalf
(
"AddEvents: %v"
,
err
)
...
@@ -185,7 +189,7 @@ func runReadBenchmark(b *testing.B, driver string, eventsPerIP int, threadCounts
...
@@ -185,7 +189,7 @@ func runReadBenchmark(b *testing.B, driver string, eventsPerIP int, threadCounts
// Write a lot of events just to bulk up the database, but
// Write a lot of events just to bulk up the database, but
// also write a couple of records for a known IP, that we're
// also write a couple of records for a known IP, that we're
// going to read in the benchmark.
// going to read in the benchmark.
n
:=
manyEvents
n
:=
manyEvents
Bench
db
.
AddAggregate
(
randomEvents
(
n
))
db
.
AddAggregate
(
randomEvents
(
n
))
// For a bunch of random IPs, add a known (possibly large)
// For a bunch of random IPs, add a known (possibly large)
...
...
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