Skip to content

Commit

Permalink
feat: goroutines number as of cpus (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbalex authored Sep 28, 2020
1 parent ae51d06 commit 61869fb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crawler/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"net/http"
"os"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -184,17 +185,20 @@ func (c *Crawler) crawl() error {

defer c.publishersWg.Wait()

// Get cpus number
numCPUs := runtime.NumCPU()

// Process the repositories in order to retrieve the files.
for i := 0 ; i < 5 ; i++ {
for i := 0; i < numCPUs; i++ {
c.repositoriesWg.Add(1)
go c.ProcessRepositories(reposChan)
}

for repo := range c.repositories {
reposChan <- repo
reposChan <- repo
}
close(reposChan)
c.repositoriesWg.Wait();
c.repositoriesWg.Wait()

// ElasticFlush to flush all the operations on ES.
err := elastic.Flush(c.index, c.es)
Expand Down

0 comments on commit 61869fb

Please sign in to comment.