Skip to content

Commit 3968c8b

Browse files
authored
Allow configuring processor concurrency (#281)
1 parent bbd8a10 commit 3968c8b

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

bitmagnet.io/setup/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ nav_order: 2
1717
- `log.level` (default: `info`): If you're developing or just curious then you may want to set this to `debug`; note that `debug` output will be very verbose.
1818
- `log.development` (default: `false`): If you're developing you may want to enable this flag to enable more verbose output such as stack traces.
1919
- `log.json` (default: `false`): By default logs are output in a pretty format with colors; enable this flag if you'd prefer plain JSON.
20-
- `log.file_rotator.enabled` (default: `false`): If true, logs will be output to rotating log files at level `log.file_rotator.level` in the `log.file_rotator.path` directory, allowing forwarding to a logs aggregator (see [the observability guide](/internals-development/observability-telemetry.html)).
20+
- `log.file_rotator.enabled` (default: `false`): If true, logs will be output to rotating log files at level `log.file_rotator.level` in the `log.file_rotator.path` directory, allowing forwarding to a logs aggregator (see [the observability guide](/guides/observability-telemetry.html)).
2121
- `http_server.options` (default `["*"]`): A list of enabled HTTP server components. By default all are enabled. Components include: `cors`, `pprof`, `graphql`, `import`, `prometheus`, `torznab`, `status`, `webui`.
2222
- `dht_crawler.scaling_factor` (default: `10`): There are various rate and concurrency limits associated with the DHT crawler. This parameter is a rough proxy for resource usage of the crawler; concurrency and buffer size of the various pipeline channels are multiplied by this value. Diminishing returns may result from exceeding the default value of 10. Since the software has not been tested on a wide variety of hardware and network conditions your mileage may vary here...
23+
- `processor.concurrency` (default: `3`): Defines the maximum number of torrents to be processed/classified simultaneously. If you experience slowdowns when the queue is working, try decreasing this to 1; conversely, if running on more powerful hardware and you'd like to work through the queue more quickly, try increasing the value.
2324

2425
To see a full list of available configuration options using the CLI, run:
2526

internal/processor/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package processor
2+
3+
type Config struct {
4+
Concurrency uint
5+
}
6+
7+
func NewDefaultConfig() Config {
8+
return Config{
9+
Concurrency: 3,
10+
}
11+
}

internal/processor/processorfx/module.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processorfx
22

33
import (
4+
"github.com/bitmagnet-io/bitmagnet/internal/boilerplate/config/configfx"
45
"github.com/bitmagnet-io/bitmagnet/internal/processor"
56
batchqueue "github.com/bitmagnet-io/bitmagnet/internal/processor/batch/queue"
67
"github.com/bitmagnet-io/bitmagnet/internal/processor/hook_0_9_0"
@@ -11,6 +12,7 @@ import (
1112
func New() fx.Option {
1213
return fx.Module(
1314
"processor",
15+
configfx.NewConfigModule[processor.Config]("processor", processor.NewDefaultConfig()),
1416
fx.Provide(
1517
processor.New,
1618
processorqueue.New,

internal/processor/queue/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
type Params struct {
1515
fx.In
16+
Config processor.Config
1617
Processor lazy.Lazy[processor.Processor]
1718
}
1819

@@ -34,7 +35,7 @@ func New(p Params) Result {
3435
return err
3536
}
3637
return pr.Process(ctx, *msg)
37-
}, handler.JobTimeout(time.Second*60*10), handler.Concurrency(3)), nil
38+
}, handler.JobTimeout(time.Second*60*10), handler.Concurrency(int(p.Config.Concurrency))), nil
3839
}),
3940
}
4041
}

0 commit comments

Comments
 (0)