fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

all: Use GOMAXPROCS instead of NumCPU

Now that GOMAXPROCS is set to match Linux CPU quota, it makes more sense to
limit concurrency based on NumCPU than GOMAXPROCS. Additionally, this allows
users to tune the amount of concurrency Zoekt uses via the GOMAXPROCS
environment variable if needs be. Ran

gofmt -w -r 'runtime.NumCPU() -> runtime.GOMAXPROCS(0)' .

Change-Id: I11e6ee63cbc8ea8da2cecc22a7e614dc6eebb4be

+5 -5
+1 -1
cmd/zoekt-indexserver/main.go
··· 71 71 log.Fatal("cpu_fraction must be between 0.0 and 1.0") 72 72 } 73 73 74 - o.cpuCount = int(math.Trunc(float64(runtime.NumCPU()) * o.cpuFraction)) 74 + o.cpuCount = int(math.Trunc(float64(runtime.GOMAXPROCS(0)) * o.cpuFraction)) 75 75 if o.cpuCount < 1 { 76 76 o.cpuCount = 1 77 77 }
+3 -3
shards/shards.go
··· 59 59 // NewDirectorySearcher returns a searcher instance that loads all 60 60 // shards corresponding to a glob into memory. 61 61 func NewDirectorySearcher(dir string) (zoekt.Searcher, error) { 62 - ss := newShardedSearcher(int64(runtime.NumCPU())) 62 + ss := newShardedSearcher(int64(runtime.GOMAXPROCS(0))) 63 63 tl := &throttledLoader{ 64 64 ss: ss, 65 - throttle: make(chan struct{}, runtime.NumCPU()), 65 + throttle: make(chan struct{}, runtime.GOMAXPROCS(0)), 66 66 } 67 67 _, err := NewDirectoryWatcher(dir, tl) 68 68 if err != nil { ··· 163 163 feeder <- s 164 164 } 165 165 close(feeder) 166 - for i := 0; i < runtime.NumCPU(); i++ { 166 + for i := 0; i < runtime.GOMAXPROCS(0); i++ { 167 167 go func() { 168 168 for s := range feeder { 169 169 searchOneShard(childCtx, s, q, opts, all)
+1 -1
shards/shards_test.go
··· 115 115 func TestOrderByShard(t *testing.T) { 116 116 ss := newShardedSearcher(1) 117 117 118 - n := 10 * runtime.NumCPU() 118 + n := 10 * runtime.GOMAXPROCS(0) 119 119 for i := 0; i < n; i++ { 120 120 ss.replace(fmt.Sprintf("shard%d", i), 121 121 &rankSearcher{