This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
many_tasks_test.go
160 lines (136 loc) · 4.23 KB
/
many_tasks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package fezzik_test
import (
"encoding/json"
"fmt"
"net"
"net/http"
"regexp"
"sync"
"sync/atomic"
"time"
"github.com/onsi/gomega/ghttp"
"code.cloudfoundry.org/bbs/models"
. "code.cloudfoundry.org/fezzik"
"code.cloudfoundry.org/gunk/workpool"
"code.cloudfoundry.org/lager"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func NewLightweightTask(guid string, addr string) *models.Task {
return &models.Task{
TaskGuid: guid,
Domain: domain,
TaskDefinition: &models.TaskDefinition{
RootFs: rootFS,
Action: models.WrapAction(&models.RunAction{
Path: "bash",
Args: []string{"-c", fmt.Sprintf("echo '%s' > /tmp/output", guid)},
User: "vcap",
}),
CompletionCallbackUrl: fmt.Sprintf("http://%s/done", addr),
DiskMb: 64,
MemoryMb: 64,
EgressRules: []*models.SecurityGroupRule{
{
Protocol: models.AllProtocol,
Destinations: []string{"0.0.0.0/0"},
},
},
ResultFile: "/tmp/output",
},
}
}
func TasksByDomainFetcher(logger lager.Logger, domain string) func() ([]*models.Task, error) {
return func() ([]*models.Task, error) {
return bbsClient.TasksByDomain(logger, domain)
}
}
func safeWait(wg *sync.WaitGroup) chan struct{} {
c := make(chan struct{})
go func() {
wg.Wait()
close(c)
}()
return c
}
func NewGHTTPServer() (*ghttp.Server, string) {
server := ghttp.NewUnstartedServer()
l, err := net.Listen("tcp", "0.0.0.0:0")
Expect(err).NotTo(HaveOccurred())
server.HTTPTestServer.Listener = l
server.HTTPTestServer.Start()
re := regexp.MustCompile(`:(\d+)$`)
port := re.FindStringSubmatch(server.URL())[1]
Expect(port).NotTo(BeZero())
//for bosh-lite only -- need something more sophisticated later.
return server, fmt.Sprintf("%s:%s", publiclyAccessibleIP, port)
}
var _ = Describe("Running Many Tasks", func() {
for _, factor := range []int{5, 200} {
factor := factor
/*
Commentary:
Currently, this test shows a degradation in performance as `factor` increases.
On Bosh-Lite I've traced this down to degrading Garden performance when many containers are created concurrently.
This is unsuprising and is likely disk-io bound. None of the degredation appears to be related to Diego's scheduling however.
*/
Context("when the tasks are lightweight (no downloads, no uploads)", func() {
var workPool *workpool.WorkPool
var tasks []*models.Task
var taskReporter *TaskReporter
var server *ghttp.Server
BeforeEach(func() {
numTasks := factor * numCells
var addr string
var err error
workPool, err = workpool.NewWorkPool(numTasks)
Expect(err).NotTo(HaveOccurred())
server, addr = NewGHTTPServer()
tasks = []*models.Task{}
for i := 0; i < numTasks; i++ {
tasks = append(tasks, NewLightweightTask(fmt.Sprintf("%s-%d", guid, i), addr))
}
cells, err := bbsClient.Cells(logger)
Expect(err).NotTo(HaveOccurred())
reportName := fmt.Sprintf("Running %d Tasks Across %d Cells", len(tasks), numCells)
taskReporter = NewTaskReporter(reportName, len(tasks), cells)
})
AfterEach(func() {
workPool.Stop()
taskReporter.EmitSummary()
taskReporter.Save()
})
It(fmt.Sprintf("should handle numCellx%d concurrent tasks", factor), func() {
allCompleted := make(chan struct{})
completionCounter := int64(0)
server.RouteToHandler("POST", "/done", func(w http.ResponseWriter, req *http.Request) {
defer func() {
if atomic.AddInt64(&completionCounter, 1) >= int64(len(tasks)) {
close(allCompleted)
}
}()
var receivedTask *models.Task
json.NewDecoder(req.Body).Decode(&receivedTask)
taskReporter.Completed(receivedTask)
})
wg := &sync.WaitGroup{}
wg.Add(len(tasks))
for _, task := range tasks {
task := task
workPool.Submit(func() {
defer wg.Done()
err := bbsClient.DesireTask(logger, task.TaskGuid, task.Domain, task.TaskDefinition)
if err != nil {
fmt.Println(err.Error())
return
}
taskReporter.DidCreate(task.TaskGuid)
})
}
Eventually(safeWait(wg), 4*time.Minute).Should(BeClosed())
Eventually(allCompleted, 30*time.Minute).Should(BeClosed())
Eventually(TasksByDomainFetcher(logger, domain), 4*time.Minute).Should(BeEmpty())
})
})
}
})