Skip to content

Commit

Permalink
Fix #467. Rework number of workers setting. Set max to 64
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Sep 25, 2023
1 parent cfaf6ab commit 02ee700
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
30 changes: 20 additions & 10 deletions src/lib/nffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,33 @@ int Init_nffile(int workers, queue_t *fileList) {
#endif

atomic_init(&blocksInUse, 0);
long CoresOnline;
if (workers)
CoresOnline = workers;
else
CoresOnline = sysconf(_SC_NPROCESSORS_ONLN);

// get conf value for maxworkers
int confMaxWorkers = ConfGetValue("maxworkers");
if (confMaxWorkers == 0) confMaxWorkers = DEFAULTWORKERS;

// set to default if not set
if (workers == 0) workers = confMaxWorkers;

long CoresOnline = sysconf(_SC_NPROCESSORS_ONLN);
if (CoresOnline < 0) {
LogError("sysconf() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno));
LogError("sysconf(_SC_NPROCESSORS_ONLN) error in %s line %d: %s", __FILE__, __LINE__, strerror(errno));
CoresOnline = DEFAULTWORKERS;
}

int confMaxWorkers = ConfGetValue("maxworkers");
dbg_printf("MAXWORKERS: %d\n", confMaxWorkers);
// no more than cores online
if (workers > CoresOnline) {
LogError("Number of workers should not be greater than number of cores online. %d is > %d", workers, CoresOnline);
workers = CoresOnline;
}

if (confMaxWorkers <= 0) confMaxWorkers = MAXWORKERS;
// no more than internal array limit
if (workers > MAXWORKERS) {
LogError("Number of workers is limited to %s", MAXWORKERS);
workers = MAXWORKERS;
}

NumWorkers = CoresOnline > confMaxWorkers ? confMaxWorkers : CoresOnline;
NumWorkers = workers;
return 1;

} // End of Init_nffile
Expand Down
2 changes: 1 addition & 1 deletion src/lib/nffile.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ typedef struct data_block_header_s {
} data_block_headerV1_t;

// allocate space for this number of workers
#define MAXWORKERS 16
#define MAXWORKERS 64
// If number of CPUs can not be determined
#define DEFAULTWORKERS 4
/*
Expand Down
2 changes: 1 addition & 1 deletion src/nfdump/nfdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ int main(int argc, char **argv) {
case 'W':
CheckArgLen(optarg, 16);
worker = atoi(optarg);
if (worker <= 0 || worker > MAXWORKERS) {
if (worker < 0 || worker > MAXWORKERS) {
LogError("Number of working threads out of range 1..%d", MAXWORKERS);
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit 02ee700

Please sign in to comment.