Skip to content

Commit 073873a

Browse files
committed
Removed sparse utilitization.go file
1 parent d6c878f commit 073873a

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

dispatcher.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import (
55
"time"
66
)
77

8+
type Utilization struct {
9+
ByWorker []WorkerUtilization
10+
PercentUtilization float32
11+
}
12+
13+
type WorkerUtilization struct {
14+
PercentUtilization float32
15+
Id int
16+
}
17+
818
func NewDispatcher(
919
maxJobQueueSize,
1020
maxWorkers int,

split.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package work
22

33
import "math"
44

5-
// Split will make "parts" evenly-sized slices, with the last slice
6-
// smaller than the others in the event len(data) is not divisible by
7-
// parts
5+
// Split will make "parts" evenly-sized slices, with the last slice smaller than the others in the event len(data) is
6+
// not divisible by parts
87
func Split(data []interface{}, parts int) [][]interface{} {
98
if parts < 2 {
109
return [][]interface{}{ data }

utilization.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

worker.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ type Job struct {
99
Context interface{}
1010
}
1111

12-
// provides a mechanism for shared data and context across calls to the work function
12+
// Context provides a mechanism for shared data and context across calls to the work function, as well as to provide
13+
// the id of the worker for tracking/logging purposes to the job functions
1314
type Context struct {
1415
Data interface{}
1516
Id int
@@ -42,6 +43,7 @@ type Worker struct {
4243
workerContext Context
4344
}
4445

46+
// GetRunningCount returns the total number of running workers this worker should count as (either 1 or 0)
4547
func (w Worker) GetRunningCount() int32 {
4648
return w.runningCount
4749
}
@@ -51,17 +53,17 @@ func (w Worker) GetRunTimeNs() int64 {
5153
return time.Now().Sub(w.startTime).Nanoseconds()
5254
}
5355

54-
// how long the worker spent doing things across all runs
56+
// GetTotalActiveTimeNs returns how long the worker spent doing things across all runs
5557
func (w Worker) GetTotalActiveTimeNs() int64 {
5658
return w.totalProcessingTimeNs
5759
}
5860

59-
// how long the worker spent doing nothing across all runs
61+
// GetTotalIdleTimeNs returns how long the worker spent doing nothing across all runs
6062
func (w Worker) GetTotalIdleTimeNs() int64 {
6163
return time.Now().Sub(w.startTime).Nanoseconds() - w.GetTotalActiveTimeNs()
6264
}
6365

64-
// how much of the time the worker spent doing things across all runs, by %
66+
// GetPercentUtilization returns how much of the time the worker spent doing things across all runs, by %
6567
func (w Worker) GetPercentUtilization() float32 {
6668
if w.GetRunTimeNs() == 0 {
6769
return 0.0
@@ -80,22 +82,22 @@ func (w *Worker) start() {
8082
case job := <-w.jobQueue:
8183
workFnStart := time.Now()
8284
atomic.AddInt32(&w.runningCount, 1)
83-
_, _ = w.log("worker%d: started job", w.workerContext.Id)
85+
w.log("worker%d: started job", w.workerContext.Id)
8486
err := w.workFn(job, &w.workerContext)
8587
atomic.AddInt32(&w.runningCount, -1)
8688
atomic.AddInt64(&w.totalProcessingTimeNs, time.Now().Sub(workFnStart).Nanoseconds())
8789

8890
if err != nil {
89-
_, _ = w.log("worker%d: had error: %s", w.workerContext.Id, err.Error())
91+
w.log("worker%d: had error: %s", w.workerContext.Id, err.Error())
9092
w.error(job, &w.workerContext, err)
9193
}
9294

9395
// nil out data to clue GC
9496
job.Context = nil
9597

96-
_, _ = w.log("worker%d: completed job", w.workerContext.Id)
98+
w.log("worker%d: completed job", w.workerContext.Id)
9799
case <-w.quitChan:
98-
_, _ = w.log("worker%d stopping", w.workerContext.Id)
100+
w.log("worker%d stopping", w.workerContext.Id)
99101
return
100102
}
101103
}
@@ -108,12 +110,10 @@ func (w Worker) stop() {
108110
}()
109111
}
110112

111-
func (w Worker) log(format string, a ...interface{}) (n int, err error) {
113+
func (w Worker) log(format string, a ...interface{}) {
112114
if w.logFn != nil {
113-
return w.logFn(format, a...)
115+
_, _ = w.logFn(format, a...)
114116
}
115-
116-
return 0, nil
117117
}
118118

119119
func (w Worker) error(job Job, workerContext *Context, err error) {

0 commit comments

Comments
 (0)