Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main-with-performance-tests-with-nick #4572

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions components/camera/collector-diff.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/data/collector.go b/data/collector.go
index 707014114..a7a2544ec 100644
--- a/data/collector.go
+++ b/data/collector.go
@@ -78,6 +78,12 @@ type collector struct {
captureFunc CaptureFunc
target CaptureBufferedWriter
lastLoggedErrors map[string]int64
+
+ lastCaptureTime time.Time
+ captureCount int64
+ captureMutex sync.Mutex
+ runningFrequency float64
+ alpha float64
}

// Close closes the channels backing the Collector. It should always be called before disposing of a Collector to avoid
@@ -196,6 +202,25 @@ func (c *collector) getAndPushNextReading() {
return
}

+ // debug freq calculation
+ c.captureMutex.Lock()
+ defer c.captureMutex.Unlock()
+
+ if !c.lastCaptureTime.IsZero() {
+ elapsed := timeReceived.AsTime().Sub(c.lastCaptureTime).Seconds()
+ if elapsed > 0 {
+ frequency := 1.0 / elapsed
+ if c.runningFrequency == 0 {
+ c.runningFrequency = frequency
+ } else {
+ c.runningFrequency = c.alpha*frequency + (1-c.alpha)*c.runningFrequency
+ }
+ c.logger.Infow("capture frequency", "frequency_hz", frequency, "running_average_hz", c.runningFrequency)
+ }
+ }
+ c.lastCaptureTime = timeReceived.AsTime()
+ c.captureCount++
+
var msg v1.SensorData
switch v := reading.(type) {
case []byte:
@@ -279,6 +304,7 @@ func NewCollector(captureFunc CaptureFunc, params CollectorParams) (Collector, e
target: params.Target,
clock: c,
lastLoggedErrors: make(map[string]int64, 0),
+ alpha: 0.1,
}, nil
}

19 changes: 19 additions & 0 deletions data/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type collector struct {
captureFunc CaptureFunc
target CaptureBufferedWriter
lastLoggedErrors map[string]int64

lastCaptureTime time.Time
}

// Close closes the channels backing the Collector. It should always be called before disposing of a Collector to avoid
Expand Down Expand Up @@ -182,6 +184,8 @@ func (c *collector) getAndPushNextReading() {
timeRequested := timestamppb.New(c.clock.Now().UTC())
reading, err := c.captureFunc(c.cancelCtx, c.params)
timeReceived := timestamppb.New(c.clock.Now().UTC())
latency := timeReceived.AsTime().Sub(timeRequested.AsTime())
elapsed := timeReceived.AsTime().Sub(c.lastCaptureTime).Seconds()

if c.cancelCtx.Err() != nil {
return
Expand All @@ -196,6 +200,21 @@ func (c *collector) getAndPushNextReading() {
return
}

// debug on success
if !c.lastCaptureTime.IsZero() {
if elapsed > 0 {
frequency := 1.0 / elapsed
c.logger.Infow("capture metrics",
"frequency_hz", frequency,
"latency_ms", latency.Milliseconds(),
"time_received", timeReceived.AsTime(),
)
} else {
panic("oh no")
}
}
c.lastCaptureTime = timeReceived.AsTime()

var msg v1.SensorData
switch v := reading.(type) {
case []byte:
Expand Down
9 changes: 9 additions & 0 deletions web/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
package main

import (
"log"
"net/http"

"go.viam.com/utils"

// registers all components.
_ "go.viam.com/rdk/components/register"
"go.viam.com/rdk/logging"

// registers all services.
_ "net/http/pprof"

_ "go.viam.com/rdk/services/register"
"go.viam.com/rdk/web/server"
)

var logger = logging.NewDebugLogger("entrypoint")

func main() {
go func() {
log.Println(http.ListenAndServe("0.0.0.0:6061", nil))
}()
utils.ContextualMain(server.RunServer, logger)
}
Loading