Skip to content

Commit

Permalink
add --response-workers flag to allow it to vary from request workers
Browse files Browse the repository at this point in the history
  • Loading branch information
tednaleid committed Apr 30, 2017
1 parent d082643 commit b6c8ca4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Config struct {
NoColor bool
BaseDirectory string
RequestWorkers int
ResponseWorkers int
SubdirLength int
RequestMethod string
ConnectTimeoutSeconds int
Expand Down
12 changes: 12 additions & 0 deletions execcontext/execcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Context struct {
BaseDirectory string
SubdirLength int
RequestWorkers int
ResponseWorkers int
ConnectTimeoutDuration time.Duration
Retries int
Logger *logger.LeveledLogger
Expand All @@ -35,11 +36,22 @@ func New(conf *config.Config) (*Context, error) {
BaseDirectory: conf.BaseDirectory,
SubdirLength: conf.SubdirLength,
RequestWorkers: conf.RequestWorkers,
ResponseWorkers: conf.ResponseWorkers,
RequestHeaders: conf.RequestHeaders,
Out: log.New(os.Stdout, "", 0),
Logger: createLeveledLogger(conf),
}

if context.RequestWorkers <= 0 {
context.RequestWorkers = 30
}

if context.ResponseWorkers <= 0 {
context.ResponseWorkers = context.RequestWorkers
}

context.Logger.Info("request workers %d, response workers %d", context.RequestWorkers, context.ResponseWorkers)

context.UrlScanner, err = createUrlScanner(conf.UrlFilename, context.Logger)

if len(conf.BaseDirectory) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func createApp() *cli.App {
Value: conf.RequestWorkers,
Destination: &conf.RequestWorkers,
},
cli.IntFlag{
Name: "response-workers",
Usage: "number of concurrent workers that will be processing responses, if not specified will be same as --workers",
Destination: &conf.ResponseWorkers,
},
cli.IntFlag{
Name: "subdir-length, S",
Usage: "length of hashed subdirectory name to put saved files when using -o; use 2 for > 5k urls, 4 for > 5M urls",
Expand Down
9 changes: 5 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ func TestAddHeadersToRequestCreatesCanonicalKeys(t *testing.T) {

func newTestContext(scaffold *Scaffold, expectedURLPaths []string) *execcontext.Context {
return &execcontext.Context{
RequestWorkers: 1,
UrlScanner: urlsScanner(expectedURLPaths),
Out: scaffold.StandardOutMock,
Logger: logger.NewPlainLeveledLogger(scaffold.LoggerMock),
RequestWorkers: 1,
ResponseWorkers: 1,
UrlScanner: urlsScanner(expectedURLPaths),
Out: scaffold.StandardOutMock,
Logger: logger.NewPlainLeveledLogger(scaffold.LoggerMock),
}
}

Expand Down
4 changes: 2 additions & 2 deletions responses/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

func StartResponseWorkers(responses <-chan *http.Response, context *execcontext.Context) *sync.WaitGroup {
var responseWaitGroup sync.WaitGroup
responseWaitGroup.Add(context.RequestWorkers)
responseWaitGroup.Add(context.ResponseWorkers)

for i := 1; i <= context.RequestWorkers; i++ {
for i := 1; i <= context.ResponseWorkers; i++ {
go func() {
if context.WriteFiles {
responseSavingWorker(responses, context)
Expand Down

0 comments on commit b6c8ca4

Please sign in to comment.