master.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "errors"
  4. "flag"
  5. "io/ioutil"
  6. "log"
  7. "strings"
  8. )
  9. func main() {
  10. if err := xmain(); err != nil {
  11. log.Fatalf("fatal error: %v", err)
  12. }
  13. }
  14. func xmain() error {
  15. workerService := flag.String("worker-service", "", "Name of worker service")
  16. chunks := flag.Int("chunks", 0, "Number of chunks")
  17. input := flag.String("input", "", "Path to input file")
  18. randSeed := flag.Int64("rand-seed", int64(0), "Random seed")
  19. shuffle := flag.Bool("shuffle", false, "Shuffle the input so as to mitigate makespan nonuniformity")
  20. flag.Parse()
  21. if *workerService == "" {
  22. return errors.New("worker-service unset")
  23. }
  24. if *chunks == 0 {
  25. return errors.New("chunks unset")
  26. }
  27. if *input == "" {
  28. return errors.New("input unset")
  29. }
  30. tests, err := loadTests(*input)
  31. if err != nil {
  32. return err
  33. }
  34. testChunks := chunkTests(tests, *chunks, *shuffle, *randSeed)
  35. log.Printf("Loaded %d tests (%d chunks)", len(tests), len(testChunks))
  36. return executeTests(*workerService, testChunks)
  37. }
  38. func chunkTests(tests []string, numChunks int, shuffle bool, randSeed int64) [][]string {
  39. // shuffling (experimental) mitigates makespan nonuniformity
  40. // Not sure this can cause some locality problem..
  41. if shuffle {
  42. shuffleStrings(tests, randSeed)
  43. }
  44. return chunkStrings(tests, numChunks)
  45. }
  46. func loadTests(filename string) ([]string, error) {
  47. b, err := ioutil.ReadFile(filename)
  48. if err != nil {
  49. return nil, err
  50. }
  51. var tests []string
  52. for _, line := range strings.Split(string(b), "\n") {
  53. s := strings.TrimSpace(line)
  54. if s != "" {
  55. tests = append(tests, s)
  56. }
  57. }
  58. return tests, nil
  59. }