Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samjjc committed Jan 14, 2018
1 parent 14d607d commit f7392a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ func normalBalancer(b *testing.B, job func() int) {
done := make(chan *Worker)
pool := NewPool(4, done)
balancer := Balancer{*pool, done, false}
b.ResetTimer()
go balancer.balance(work)
for n := 0; n < b.N; n++ {
FiniteRequests(work, job, 20)
FiniteRequests(work, job, 100)
}
}

func workSingleThread(b *testing.B, job func() int) {
jobsRepeats := 20
singleWorker := make(chan Request, 20)
jobsRepeats := 100
singleWorker := make(chan Request, 100)
for n := 0; n < b.N; n++ {
go func() {
for i := 0; i < jobsRepeats; i++ {
Expand Down
2 changes: 1 addition & 1 deletion errorString.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type ErrorString struct {
}

func (e ErrorString) Error() string {
return fmt.Sprintf("Work Failed: %s", e.s)
return fmt.Sprintf("Error: %s", e.s)
}
3 changes: 2 additions & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Pool []*Worker
func NewPool(size int, done chan *Worker) *Pool {
var pool Pool
for i := 0; i < size; i++ {
requests := make(chan Request, 30)
requests := make(chan Request, 300)
worker := Worker{requests, 0, i}
go worker.work(done)
pool = append(pool, &worker)
Expand All @@ -25,6 +25,7 @@ func (p Pool) String() string {
s := "Pool: "
for _, v := range p {
s += fmt.Sprint(" ", v.pending)
s += fmt.Sprint(" ", len(v.requests))
}
return s
}
Expand Down
4 changes: 2 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Request struct {

//InfiniteRequester sends custom requests to the work channel every 0.1 to 0.4 seconds
func InfiniteRequester(work chan<- Request, job func() int) {
c := make(chan int, 5)
c := make(chan int, 25)
e := make(chan error, 5)
for {
randDuration := time.Duration(rand.Intn(300)) * time.Millisecond
Expand Down Expand Up @@ -46,7 +46,7 @@ func constantJob() int {
}

func fastJob() int {
y := rand.Intn(4000) / 5
y := rand.Intn(1000)
x := 2 * y
return x
}

0 comments on commit f7392a0

Please sign in to comment.