| 186 | } |
| 187 | |
| 188 | func (s *S) BenchmarkScanLogs(c *check.C) { |
| 189 | c.StopTimer() |
| 190 | var apps []appTypes.App |
| 191 | for i := 0; i < 100; i++ { |
| 192 | a := appTypes.App{Name: fmt.Sprintf("myapp-%d", i), Platform: "zend", TeamOwner: s.team.Name} |
| 193 | apps = append(apps, a) |
| 194 | err := app.CreateApp(context.TODO(), &a, s.user) |
| 195 | c.Assert(err, check.IsNil) |
| 196 | } |
| 197 | baseMsg := `{"date": "2015-06-16T15:00:00.000Z", "message": "msg-%d", "source": "web", "appname": "%s", "unit": "unit1"}` + "\n" |
| 198 | for i := range apps { |
| 199 | // Remove overhead for first message from app from benchmark. |
| 200 | err := scanLogs(strings.NewReader(fmt.Sprintf(baseMsg, 0, apps[i].Name))) |
| 201 | c.Assert(err, check.IsNil) |
| 202 | } |
| 203 | c.StartTimer() |
| 204 | r, w := io.Pipe() |
| 205 | done := make(chan struct{}) |
| 206 | go func() { |
| 207 | defer close(done) |
| 208 | err := scanLogs(r) |
| 209 | if err != nil { |
| 210 | c.Fatal(err) |
| 211 | } |
| 212 | }() |
| 213 | for i := 0; i < c.N; i++ { |
| 214 | msg := fmt.Sprintf(baseMsg, i, apps[i%len(apps)].Name) |
| 215 | _, err := w.Write([]byte(msg)) |
| 216 | if err != nil { |
| 217 | c.Fatal(err) |
| 218 | } |
| 219 | } |
| 220 | w.Close() |
| 221 | <-done |
| 222 | c.StopTimer() |
| 223 | servicemanager.LogService.(shutdown.Shutdownable).Shutdown(context.Background()) |
| 224 | var err error |
| 225 | servicemanager.LogService, err = applog.AppLogService() |
| 226 | c.Assert(err, check.IsNil) |
| 227 | } |