Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Refactor for speed control #4986

Merged
merged 17 commits into from
Apr 9, 2024
Merged

Conversation

Mzack9999
Copy link
Member

@Mzack9999 Mzack9999 commented Apr 3, 2024

Proposed changes

Due to the impact of internal changes (remove callbacks, move components from static to component-field and pass via dep-injection) the original PR is put On Hold, and a lighter approach for speed control is implemented here. The speed control will be performed with the following points:

  • Deprecating RateLimitPerMinute and adding RateLimitDuration
  • Speed control via SDK through types.Option options:
    • BulkSize
    • Threads
    • PayloadConcurrency
    • JsConcurrency
    • RateLimit
    • RateLimitDuration
  • Any variation to these settings will be reflected internally to existing and new worker pools at next internal useful iteration (for example changing the bulk size will reflect the next time the internal engine iterate over a new template)

In order to allow autotuning it's first necessary to resolve internal design issues to allow smooth communication between the growing amount of components. As a follow up we can expose the speed control capability via local http endpoint (maybe the same metrics/stats one)

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@Mzack9999 Mzack9999 marked this pull request as ready for review April 5, 2024 14:47
@Mzack9999 Mzack9999 self-assigned this Apr 5, 2024
@Mzack9999 Mzack9999 linked an issue Apr 5, 2024 that may be closed by this pull request
@Mzack9999 Mzack9999 added the Type: Enhancement Most issues will probably ask for additions or changes. label Apr 5, 2024
Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm !

  • suggested 2 possible changes
  • if i am not wrong this lays a foundation for handler / controller logic which will be implemented in follow up PRs ( but as of now this is a No-OP behaviour wise )

More thoughts

  • Looking at implementation i wonder if we could have created all these sizedpools from a single type/method like types.Options or maybe a option to register a optional handler when intializing a sizedpool created a new sizedpool ex:
swg := NewSizedPool(concurrency).RegisterController("js-pool", autoModeController)

and we would have a autoModeController running in goroutine continiously monitering memory and follow a pre-defined algorithm to rebalance different sizedpools at different locations ( ex: decrease payloadconcurrency first and observe change etc )

that way this could be later on extended to implement a global nuclei level smart rate limit controller

internal/runner/inputs.go Outdated Show resolved Hide resolved
internal/runner/runner.go Outdated Show resolved Hide resolved
@Mzack9999
Copy link
Member Author

Actually it's a NO-OP only for usages from CLI, while via SDK a change within the input settings, causes the internal pools to follow the new value within types.Option. I think that via cli we can expose the control via the existing http server for stats/metrics or create a new one ad-hoc.

The centralizing of speed control was the central thought at #4919, so that the various resizable pools would have referred to a central unique controller, with the advantage that references were cleaned up automatically, while with the approach you suggested, while easier to implement, requires a very careful removal of handlers, since they are tied to a global go routine. As we have seen this is the source of endless memory issues. The biggest problem with this approach is the logic scattered into ultra-wrapped callbacks with unclear intended closures and circular references.

@Mzack9999 Mzack9999 merged commit 721ddda into dev Apr 9, 2024
12 checks passed
@Mzack9999 Mzack9999 deleted the feat-3072-init-adaptive-speed branch April 9, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Most issues will probably ask for additions or changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement auto-adaptive speed tuning
2 participants