Linux setup fixes, one pool worker per physical core on Linux, --port for installs, Monitor totals

- setup.sh is executable in the repository (a fresh clone could not run `./setup.sh`: Permission denied).
- setup.sh: Debian/Ubuntu ship Python's venv without ensurepip (the separate python3-venv package); the check
  now needs both, so it installs python3-venv instead of failing to create .venv - and a .venv left without pip
  by a failed run is made again.
- Linux: physical_cores() keeps one allowed CPU per (package, core) from sysfs, like the Windows branch; SMT
  siblings no longer get their own pool worker (issue #40: 23 -> 15 workers on a 13700K, +16% decode).
- START-HERE / setup.sh `--port N` now applies to an existing install; without it the install's own port is
  kept (issue #32).
- Monitor: the server keeps the last 500 requests and totals since it started; the Monitor shows the totals and
  a "Show all" toggle (`/metrics?requests=all`), 12 rows otherwise (issue #35).
This commit is contained in:
Niko1221 committed 2026-09-28 07:55:39 +02:00
1 parent 2838cbae46
commit ffcdb437b8
7 files changed
+96 -25

No files matched your search

+27 -2
View File
@@ -55,13 +55,38 @@ std::vector<int> physical_cores(bool skip_first) {
}
}
#else
// The logical CPUs this process may run on, ONE PER PHYSICAL CORE (issue #40): SMT siblings share a core's
// load/store bandwidth, so a worker on each would put two workers on one core, as the Windows branch above
// explains. sysfs names each CPU's (package, core); the first allowed CPU of each pair is kept, so a taskset
// that leaves out the first sibling still gets its core. Without sysfs every allowed CPU counts, as before.
auto topo = [](int cpu, const char* what) -> long {
char path[96];
std::snprintf(path, sizeof path, "/sys/devices/system/cpu/cpu%d/topology/%s", cpu, what);
long v = -1;
if (std::FILE* f = std::fopen(path, "r")) {
if (std::fscanf(f, "%ld", &v) != 1) v = -1;
std::fclose(f);
}
return v;
};
std::vector<int> allowed;
cpu_set_t set;
CPU_ZERO(&set);
if (sched_getaffinity(0, sizeof set, &set) == 0) {
for (int i = 0; i < CPU_SETSIZE; ++i)
if (CPU_ISSET(i, &set)) cores.push_back(i);
if (CPU_ISSET(i, &set)) allowed.push_back(i);
} else {
for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i);
for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) allowed.push_back((int) i);
}
std::vector<std::pair<long, long>> seen;
for (int cpu : allowed) {
const long pkg = topo(cpu, "physical_package_id"), core = topo(cpu, "core_id");
if (pkg >= 0 && core >= 0) {
const std::pair<long, long> key{pkg, core};
if (std::find(seen.begin(), seen.end(), key) != seen.end()) continue; // an SMT sibling
seen.push_back(key);
}
cores.push_back(cpu);
}
#endif
if (skip_first && !cores.empty()) cores.erase(cores.begin());