Check how many CPUs and filehandles there are instead of guessing

This commit is contained in:
Eric Fischer
2015-11-11 16:10:39 -08:00
parent 666a56d84a
commit e1f4bdd36c
3 changed files with 29 additions and 5 deletions
+24
View File
@@ -17,6 +17,7 @@
#include <limits.h>
#include <sqlite3.h>
#include <stdarg.h>
#include <sys/resource.h>
#include "jsonpull.h"
#include "tile.h"
@@ -60,6 +61,27 @@ int mb_geometry[GEOM_TYPES] = {
VT_POINT, VT_POINT, VT_LINE, VT_LINE, VT_POLYGON, VT_POLYGON,
};
int CPUS;
int TEMP_FILES;
void init_cpus() {
CPUS = sysconf(_SC_NPROCESSORS_ONLN);
if (CPUS < 1) {
CPUS = 1;
}
TEMP_FILES = 64;
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
perror("getrlimit");
} else {
TEMP_FILES = rl.rlim_cur / 3;
if (TEMP_FILES > CPUS * 4) {
TEMP_FILES = CPUS * 4;
}
}
}
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname) {
size_t w = fwrite(ptr, size, nitems, stream);
if (w != nitems) {
@@ -1167,6 +1189,8 @@ int main(int argc, char **argv) {
mtrace();
#endif
init_cpus();
extern int optind;
extern char *optarg;
int i;