projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
9587: test /trash page
[arvados.git]
/
services
/
ws
/
handler.go
diff --git
a/services/ws/handler.go
b/services/ws/handler.go
index dace39be35952c99d55e9cc89f4cefcde3978663..72291900fac52c4192f4db971e29bd736be5c189 100644
(file)
--- a/
services/ws/handler.go
+++ b/
services/ws/handler.go
@@
-2,12
+2,12
@@
package main
import (
"context"
import (
"context"
- "fmt"
"io"
"sync"
"time"
"git.curoverse.com/arvados.git/sdk/go/arvados"
"io"
"sync"
"time"
"git.curoverse.com/arvados.git/sdk/go/arvados"
+ "git.curoverse.com/arvados.git/sdk/go/stats"
)
type handler struct {
)
type handler struct {
@@
-16,7
+16,7
@@
type handler struct {
QueueSize int
mtx sync.Mutex
QueueSize int
mtx sync.Mutex
- lastDelay map[chan interface{}]
time
.Duration
+ lastDelay map[chan interface{}]
stats
.Duration
setupOnce sync.Once
}
setupOnce sync.Once
}
@@
-27,10
+27,11
@@
type handlerStats struct {
EventCount uint64
}
EventCount uint64
}
-func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsConn, chan<- interface{}) (session, error)) (
s
tats handlerStats) {
+func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsConn, chan<- interface{}) (session, error)) (
hS
tats handlerStats) {
h.setupOnce.Do(h.setup)
ctx, cancel := context.WithCancel(ws.Request().Context())
h.setupOnce.Do(h.setup)
ctx, cancel := context.WithCancel(ws.Request().Context())
+ defer cancel()
log := logger(ctx)
incoming := eventSource.NewSink()
log := logger(ctx)
incoming := eventSource.NewSink()
@@
-52,6
+53,8
@@
func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
return
}
return
}
+ // Receive websocket frames from the client and pass them to
+ // sess.Receive().
go func() {
buf := make([]byte, 2<<20)
for {
go func() {
buf := make([]byte, 2<<20)
for {
@@
-83,6
+86,9
@@
func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
}
}()
}
}()
+ // Take items from the outgoing queue, serialize them using
+ // sess.EventMessage() as needed, and send them to the client
+ // as websocket frames.
go func() {
for {
var ok bool
go func() {
for {
var ok bool
@@
-132,14
+138,14
@@
func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
log.Debug("sent")
if e != nil {
log.Debug("sent")
if e != nil {
-
s
tats.QueueDelayNs += t0.Sub(e.Ready)
+
hS
tats.QueueDelayNs += t0.Sub(e.Ready)
h.mtx.Lock()
h.mtx.Lock()
- h.lastDelay[queue] =
time.Since(e.Ready
)
+ h.lastDelay[queue] =
stats.Duration(time.Since(e.Ready)
)
h.mtx.Unlock()
}
h.mtx.Unlock()
}
-
s
tats.WriteDelayNs += time.Since(t0)
-
s
tats.EventBytes += uint64(len(buf))
-
s
tats.EventCount++
+
hS
tats.WriteDelayNs += time.Since(t0)
+
hS
tats.EventBytes += uint64(len(buf))
+
hS
tats.EventCount++
}
}()
}
}()
@@
-192,7
+198,7
@@
func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
return
}
return
}
-func (h *handler) Status() interface{} {
+func (h *handler)
Debug
Status() interface{} {
h.mtx.Lock()
defer h.mtx.Unlock()
h.mtx.Lock()
defer h.mtx.Unlock()
@@
-201,10
+207,8
@@
func (h *handler) Status() interface{} {
QueueMin int
QueueMax int
QueueTotal uint64
QueueMin int
QueueMax int
QueueTotal uint64
- queueDelayMin time.Duration
- QueueDelayMin string
- queueDelayMax time.Duration
- QueueDelayMax string
+ QueueDelayMin stats.Duration
+ QueueDelayMax stats.Duration
}
for q, lastDelay := range h.lastDelay {
s.QueueCount++
}
for q, lastDelay := range h.lastDelay {
s.QueueCount++
@@
-216,18
+220,16
@@
func (h *handler) Status() interface{} {
if s.QueueMin > n || s.QueueCount == 1 {
s.QueueMin = n
}
if s.QueueMin > n || s.QueueCount == 1 {
s.QueueMin = n
}
- if (s.
queueDelayMin > lastDelay || s.q
ueueDelayMin == 0) && lastDelay > 0 {
- s.
q
ueueDelayMin = lastDelay
+ if (s.
QueueDelayMin > lastDelay || s.Q
ueueDelayMin == 0) && lastDelay > 0 {
+ s.
Q
ueueDelayMin = lastDelay
}
}
- if s.
q
ueueDelayMax < lastDelay {
- s.
q
ueueDelayMax = lastDelay
+ if s.
Q
ueueDelayMax < lastDelay {
+ s.
Q
ueueDelayMax = lastDelay
}
}
}
}
- s.QueueDelayMin = fmt.Sprintf("%.06f", s.queueDelayMin.Seconds())
- s.QueueDelayMax = fmt.Sprintf("%.06f", s.queueDelayMax.Seconds())
return &s
}
func (h *handler) setup() {
return &s
}
func (h *handler) setup() {
- h.lastDelay = make(map[chan interface{}]
time
.Duration)
+ h.lastDelay = make(map[chan interface{}]
stats
.Duration)
}
}