Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
91f3dd0f
Commit
91f3dd0f
authored
4 years ago
by
RUANO RINCON Santiago
Browse files
Options
Downloads
Patches
Plain Diff
Write spamming time inforation to disk
parent
170dd15e
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
packages/spammer/spammer.go
+24
-5
24 additions, 5 deletions
packages/spammer/spammer.go
with
24 additions
and
5 deletions
packages/spammer/spammer.go
+
24
−
5
View file @
91f3dd0f
...
...
@@ -3,6 +3,7 @@ package spammer
import
(
"math/rand"
"os"
"strconv"
"sync/atomic"
"time"
...
...
@@ -52,9 +53,17 @@ func (spammer *Spammer) run(rate int, timeUnit time.Duration, processID int64) {
log
.
Fatal
(
err
)
}
start
:=
time
.
Now
()
_
,
err
=
fileIntervals
.
WriteString
(
"startTimestamp,"
+
"payloadTime,"
+
"endTimestamp,"
+
"remainingTime,"
+
"msgInterval
\n
"
)
for
{
start
:=
time
.
Now
()
startNano
:=
time
.
Now
()
.
UnixNano
()
if
atomic
.
LoadInt64
(
&
spammer
.
processID
)
!=
processID
{
return
}
...
...
@@ -65,19 +74,29 @@ func (spammer *Spammer) run(rate int, timeUnit time.Duration, processID int64) {
// can't issue msg because node not in sync
return
}
end
:=
time
.
Now
()
.
UnixNano
()
currentInterval
:=
time
.
Since
(
start
)
remainingTime
:=
time
.
Duration
(
0
)
// emit messages by intervals whose random duration is exponentially distributed
msgInterval
:=
time
.
Duration
(
float64
(
timeUnit
.
Nanoseconds
())
*
rand
.
ExpFloat64
()
/
float64
(
rate
))
if
currentInterval
<
msgInterval
{
remainingTime
=
msgInterval
-
currentInterval
//there is still time, sleep until msgInterval
time
.
Sleep
(
msgInterval
-
currentInterval
)
fileIntervals
.
WriteString
((
msgInterval
-
currentInterval
)
.
String
()
+
"
\n
"
)
}
else
{
fileIntervals
.
WriteString
(
"0
\n
"
)
}
// when currentInterval > msgInterval, the node can't issue msgs as fast as requested, will do as fast as it can
start
=
time
.
Now
()
_
,
err
=
fileIntervals
.
WriteString
(
strconv
.
FormatInt
(
startNano
,
10
)
+
","
+
// start timestamp
currentInterval
.
String
()
+
","
+
// time needed to send the payload
strconv
.
FormatInt
(
end
,
10
)
+
","
+
// time after sending the payload
remainingTime
.
String
()
+
","
+
// remaining time
msgInterval
.
String
()
+
"
\n
"
)
// interval between two spam messages
if
err
!=
nil
{
log
.
Fatalf
(
"Error while writing to a file. Err: %s"
,
err
.
Error
())
}
}
}
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