mirror of
https://github.com/upa/mscp.git
synced 2026-02-27 18:54:42 +08:00
set default nr_threads to floor(log(cores) * 2) + 1)
This change prevents mscp from establishing too many ssh connections on many-core machines in default.
This commit is contained in:
20
src/main.c
20
src/main.c
@@ -90,10 +90,11 @@ void usage(bool print_help) {
|
|||||||
if (!print_help)
|
if (!print_help)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf(" -n NR_CONNECTIONS number of connections (default: half of # of cpu cores)\n"
|
printf(" -n NR_CONNECTIONS number of connections "
|
||||||
|
"(default: floor(log(cores)*2)+1)\n"
|
||||||
" -m COREMASK hex value to specify cores where threads pinned\n"
|
" -m COREMASK hex value to specify cores where threads pinned\n"
|
||||||
" -s MIN_CHUNK_SIZE min chunk size (default: 64MB)\n"
|
" -s MIN_CHUNK_SIZE min chunk size (default: 64MB)\n"
|
||||||
" -S MAX_CHUNK_SIZE max chunk size (default: filesize / nr_conn)\n"
|
" -S MAX_CHUNK_SIZE max chunk size (default: filesize/nr_conn)\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -a NR_AHEAD number of inflight SFTP commands (default: 32)\n"
|
" -a NR_AHEAD number of inflight SFTP commands (default: 32)\n"
|
||||||
" -b BUF_SZ buffer size for i/o and transfer\n"
|
" -b BUF_SZ buffer size for i/o and transfer\n"
|
||||||
@@ -164,6 +165,7 @@ int expand_coremask(const char *coremask, int **cores, int *nr_cores)
|
|||||||
char c[2] = { 'x', '\0' };
|
char c[2] = { 'x', '\0' };
|
||||||
const char *_coremask;
|
const char *_coremask;
|
||||||
long v, needle;
|
long v, needle;
|
||||||
|
int ncores = nr_cpus();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function returns array of usable cores in `cores` and
|
* This function returns array of usable cores in `cores` and
|
||||||
@@ -194,6 +196,8 @@ int expand_coremask(const char *coremask, int **cores, int *nr_cores)
|
|||||||
|
|
||||||
for (needle = 0x01; needle < 0x10; needle <<= 1) {
|
for (needle = 0x01; needle < 0x10; needle <<= 1) {
|
||||||
nr_all++;
|
nr_all++;
|
||||||
|
if (nr_all > ncores)
|
||||||
|
break; /* too long coremask */
|
||||||
if (v & needle) {
|
if (v & needle) {
|
||||||
nr_usable++;
|
nr_usable++;
|
||||||
core_list = realloc(core_list, sizeof(int) * nr_usable);
|
core_list = realloc(core_list, sizeof(int) * nr_usable);
|
||||||
@@ -216,6 +220,11 @@ int expand_coremask(const char *coremask, int **cores, int *nr_cores)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int default_nr_threads()
|
||||||
|
{
|
||||||
|
return (int)(floor(log(nr_cpus()) * 2) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct ssh_opts opts;
|
struct ssh_opts opts;
|
||||||
@@ -237,8 +246,7 @@ int main(int argc, char **argv)
|
|||||||
lock_init(&m.chunk_lock);
|
lock_init(&m.chunk_lock);
|
||||||
m.nr_ahead = DEFAULT_NR_AHEAD;
|
m.nr_ahead = DEFAULT_NR_AHEAD;
|
||||||
m.buf_sz = DEFAULT_BUF_SZ;
|
m.buf_sz = DEFAULT_BUF_SZ;
|
||||||
m.nr_threads = (int)(nr_cpus() / 2);
|
m.nr_threads = default_nr_threads();
|
||||||
m.nr_threads = m.nr_threads == 0 ? 1 : m.nr_threads;
|
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "n:m:s:S:a:b:vqDl:p:i:c:M:CHdNh")) != -1) {
|
while ((ch = getopt(argc, argv, "n:m:s:S:a:b:vqDl:p:i:c:M:CHdNh")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@@ -365,6 +373,7 @@ int main(int argc, char **argv)
|
|||||||
pprint(2, " %d", cores[n]);
|
pprint(2, " %d", cores[n]);
|
||||||
pprint(2, "\n");
|
pprint(2, "\n");
|
||||||
}
|
}
|
||||||
|
pprint2("number of connections: %d\n", m.nr_threads);
|
||||||
|
|
||||||
/* create control session */
|
/* create control session */
|
||||||
m.host = find_hostname(optind, argc, argv);
|
m.host = find_hostname(optind, argc, argv);
|
||||||
@@ -405,7 +414,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* prepare thread instances */
|
/* prepare thread instances */
|
||||||
if ((n = list_count(&m.chunk_list)) < m.nr_threads) {
|
if ((n = list_count(&m.chunk_list)) < m.nr_threads) {
|
||||||
pprint3("we have only %d chunk(s). set NR_CONNECTIONS to %d\n", n, n);
|
pprint2("we have only %d chunk(s). "
|
||||||
|
"set number of connections to %d\n", n, n);
|
||||||
m.nr_threads = n;
|
m.nr_threads = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user