Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mátrix backend
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tóth Miklós Tibor
Mátrix backend
Commits
609e3f21
Commit
609e3f21
authored
Feb 24, 2021
by
Tóth Miklós Tibor
Browse files
Options
Downloads
Patches
Plain Diff
i am speed
parent
4a78b400
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
aggregator/clean.go
+0
-33
0 additions, 33 deletions
aggregator/clean.go
aggregator/collect.go
+9
-28
9 additions, 28 deletions
aggregator/collect.go
aggregator/serve.go
+25
-16
25 additions, 16 deletions
aggregator/serve.go
bench/main.go
+1
-1
1 addition, 1 deletion
bench/main.go
main.go
+3
-0
3 additions, 0 deletions
main.go
with
38 additions
and
78 deletions
aggregator/clean.go
deleted
100644 → 0
+
0
−
33
View file @
4a78b400
package
aggregator
import
(
"sync"
"time"
)
func
clean
()
{
t
:=
getTime
()
%
(
bucket
*
2
)
for
i
:=
(
t
+
2
)
%
(
bucket
*
2
);
i
!=
(
t
+
bucket
/
2
)
%
(
bucket
*
2
);
i
=
(
i
+
1
)
%
(
bucket
*
2
)
{
m
,
ok
:=
data
.
Load
(
i
)
if
!
ok
{
continue
}
timeMap
,
ok
:=
m
.
(
*
sync
.
Map
)
if
!
ok
{
continue
}
timeMap
.
Range
(
func
(
key
,
_
interface
{})
bool
{
timeMap
.
Delete
(
key
)
return
true
})
}
}
func
init
()
{
go
func
()
{
for
{
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
bucket
/
1000
/
5
))
clean
()
}
}()
}
This diff is collapsed.
Click to expand it.
aggregator/collect.go
+
9
−
28
View file @
609e3f21
package
aggregator
import
(
"flag"
"git.sch.bme.hu/mikewashere/matrix-backend/metrics"
"sync"
"time"
)
var
bucketFlag
=
flag
.
Int64
(
"bucket"
,
10000
,
"Bucket size"
)
var
bucket
int64
=
10000
var
_
=
func
()
error
{
flag
.
Parse
()
bucket
=
*
bucketFlag
return
nil
}()
func
getTime
()
int64
{
return
time
.
Now
()
.
UnixNano
()
/
1e6
type
Choice
struct
{
Choice
string
Timestamp
time
.
Time
}
// data[
getTime][
user] = choice
// data[user] = choice
var
data
sync
.
Map
func
init
()
{
for
i
:=
int64
(
0
);
i
<
bucket
*
2
;
i
++
{
data
.
Store
(
i
,
&
sync
.
Map
{})
}
}
func
Vote
(
UserID
,
Choice
string
)
{
func
Vote
(
UserID
,
choice
string
)
{
go
metrics
.
Votes
.
Inc
()
t
:=
getTime
()
%
(
bucket
*
2
)
timeMap
,
ok
:=
data
.
Load
(
t
)
if
ok
{
timeMap
,
ok
:=
timeMap
.
(
*
sync
.
Map
)
if
ok
{
timeMap
.
Store
(
UserID
,
Choice
)
}
c
:=
Choice
{
Choice
:
choice
,
Timestamp
:
time
.
Now
(),
}
data
.
Store
(
UserID
,
c
)
}
This diff is collapsed.
Click to expand it.
aggregator/serve.go
+
25
−
16
View file @
609e3f21
package
aggregator
import
(
"flag"
"git.sch.bme.hu/mikewashere/matrix-backend/db"
"git.sch.bme.hu/mikewashere/matrix-backend/metrics"
"sync"
"time"
)
func
GetCurrentChoices
()
(
map
[
string
]
map
[
string
]
int
,
error
)
{
var
stale
=
flag
.
Int
(
"stale"
,
10000
,
"the time in milliseconds after a vote becomes stale, or not counted"
)
var
staleDuration
time
.
Duration
func
init
()
{
staleDuration
=
time
.
Duration
(
*
stale
)
*
time
.
Millisecond
}
func
GetCurrentChoices
()
(
map
[
string
]
*
map
[
string
]
int
,
error
)
{
t
:=
time
.
Now
()
go
metrics
.
Requests
.
Inc
()
t
:=
getTime
()
%
(
bucket
*
2
)
ret
:=
make
(
map
[
string
]
map
[
string
]
int
)
ret
:=
make
(
map
[
string
]
*
map
[
string
]
int
)
teams
,
e
:=
db
.
GetTeamsWithMembers
()
if
e
!=
nil
{
return
nil
,
e
}
var
wg
sync
.
WaitGroup
for
_
,
team
:=
range
teams
{
wg
.
Add
(
1
)
teamMap
:=
make
(
map
[
string
]
int
)
ret
[
team
.
ID
]
=
&
teamMap
go
func
(
teamMap
*
map
[
string
]
int
,
team
*
db
.
Team
)
{
for
_
,
u
:=
range
team
.
Members
{
for
i
:=
t
;
i
!=
(
t
+
bucket
*
2
-
bucket
)
%
(
bucket
*
2
);
i
=
(
i
+
bucket
*
2
-
1
)
%
(
bucket
*
2
)
{
m
,
ok
:=
data
.
Load
(
i
)
c
,
ok
:=
data
.
Load
(
u
.
ID
)
if
ok
{
m
,
ok
:=
m
.
(
*
sync
.
Map
)
c
,
ok
:=
c
.
(
Choice
)
if
ok
{
d
,
ok
:=
m
.
Load
(
u
.
ID
)
if
ok
{
d
,
ok
:=
d
.
(
string
)
if
ok
{
teamMap
[
d
]
=
teamMap
[
d
]
+
1
}
break
}
if
t
.
Sub
(
c
.
Timestamp
)
<
staleDuration
{
(
*
teamMap
)[
c
.
Choice
]
=
(
*
teamMap
)[
c
.
Choice
]
+
1
}
}
}
}
ret
[
team
.
ID
]
=
teamMap
wg
.
Done
()
}(
&
teamMap
,
team
)
}
wg
.
Wait
()
return
ret
,
nil
}
This diff is collapsed.
Click to expand it.
bench/main.go
+
1
−
1
View file @
609e3f21
...
...
@@ -29,7 +29,7 @@ func (s *stringSlice) RandElement() string {
}
var
(
loc
=
flag
.
String
(
"location
s
"
,
"http://localhost:8080"
,
"location of server"
)
loc
=
flag
.
String
(
"location"
,
"http://localhost:8080"
,
"location of server"
)
prod
=
flag
.
Int
(
"producers"
,
100
,
"number of producers"
)
cons
=
flag
.
Int
(
"consumers"
,
1
,
"number of consumers"
)
prodInt
=
flag
.
Int
(
"prod-interval"
,
1000
,
"interval of clicks in ms"
)
...
...
This diff is collapsed.
Click to expand it.
main.go
+
3
−
0
View file @
609e3f21
package
main
import
(
"flag"
"git.sch.bme.hu/mikewashere/matrix-backend/input"
"git.sch.bme.hu/mikewashere/matrix-backend/output"
"github.com/igm/sockjs-go/v3/sockjs"
...
...
@@ -10,6 +11,8 @@ import (
)
func
main
()
{
flag
.
Parse
()
mux
:=
http
.
NewServeMux
()
opts
:=
sockjs
.
DefaultOptions
opts
.
RawWebsocket
=
true
...
...
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