Spaces:
Running
Running
JOHN SILLVESTOR commited on
optimize streaming concurrency, bot pool, and buffer limits
Browse files
server.js
CHANGED
|
@@ -37,28 +37,28 @@ function cgroupLimitBytes() {
|
|
| 37 |
const CGROUP_BYTES = cgroupLimitBytes();
|
| 38 |
const RAM_BYTES = CGROUP_BYTES || os.totalmem() || (16 * 1024 * MB);
|
| 39 |
const CHUNK_SIZE = 256 * 1024;
|
| 40 |
-
const HOT_HEAD =
|
| 41 |
-
const HOT_TAIL =
|
| 42 |
-
const STREAM_WINDOW =
|
| 43 |
const PROBE_HEAD = 4 * MB;
|
| 44 |
-
const BOT_MAX =
|
| 45 |
const PIPE_MS = 30000;
|
| 46 |
const PIPE_MAX_MS = 3 * 60 * 60 * 1000;
|
| 47 |
-
const RANGE_LOOKAHEAD =
|
| 48 |
-
const WARM_AHEAD =
|
| 49 |
-
const WARM_BUDGET_BYTES =
|
| 50 |
let warmBytesInFlight = 0;
|
| 51 |
-
const WARM_BATCH = Math.max(
|
| 52 |
-
const IP_STREAM_MAX =
|
| 53 |
-
const IP_TITLE_MAX =
|
| 54 |
-
const UID_STREAM_MAX =
|
| 55 |
-
const UID_TITLE_MAX =
|
| 56 |
-
const TITLE_PIPE_MAX =
|
| 57 |
-
const GLOBAL_PIPE_MAX =
|
| 58 |
const DISK_SLICE_DIR = "/tmp/dlk_slice";
|
| 59 |
const DISK_MAX_BYTES = 24 * 1024 * 1024 * 1024;
|
| 60 |
const DISK_FREE_MIN_BYTES = 4 * 1024 * 1024 * 1024;
|
| 61 |
-
const HOT_BYTES_MAX = Math.min(
|
| 62 |
const BODY_MAX = 262144;
|
| 63 |
const FILE_TTL = 20 * 60 * 1000;
|
| 64 |
const LVL_TTL = 60000;
|
|
@@ -513,7 +513,7 @@ function limited(ip) {
|
|
| 513 |
const key = ipNet(ip) + ":" + slot;
|
| 514 |
const n = (rateMap.get(key) || 0) + 1;
|
| 515 |
rateMap.set(key, n);
|
| 516 |
-
return n >
|
| 517 |
}
|
| 518 |
|
| 519 |
function slotOver(key, max) {
|
|
@@ -526,16 +526,16 @@ function slotOver(key, max) {
|
|
| 526 |
|
| 527 |
function mintLimited(ip) {
|
| 528 |
const s = String(ip || "0");
|
| 529 |
-
return slotOver("mint:" + s,
|
| 530 |
}
|
| 531 |
|
| 532 |
function mintBlocked(ip) {
|
| 533 |
const slot = Math.floor(Date.now() / 60000);
|
| 534 |
-
return (rateMap.get("badm:" + String(ip || "0") + ":" + slot) || 0) >
|
| 535 |
}
|
| 536 |
|
| 537 |
function mintFailed(ip) {
|
| 538 |
-
return slotOver("badm:" + String(ip || "0"),
|
| 539 |
}
|
| 540 |
|
| 541 |
function isBlogOrigin(o) {
|
|
@@ -886,8 +886,8 @@ async function startBot(token, idx) {
|
|
| 886 |
floodSleepThreshold: 2,
|
| 887 |
requestRetries: 3,
|
| 888 |
downloadRetries: 3,
|
| 889 |
-
maxConcurrentDownloads:
|
| 890 |
-
downloadPool: { inflightPerDc:
|
| 891 |
});
|
| 892 |
client.setLogLevel("error");
|
| 893 |
await client.start({ botAuthToken: token });
|
|
@@ -3409,7 +3409,7 @@ async function main() {
|
|
| 3409 |
requestTimeout: 0,
|
| 3410 |
connectionsCheckingInterval: 10000
|
| 3411 |
}, onReq);
|
| 3412 |
-
srv.maxConnections =
|
| 3413 |
srv.timeout = 0;
|
| 3414 |
srv.on("clientError", (err, sock) => {
|
| 3415 |
try {
|
|
|
|
| 37 |
const CGROUP_BYTES = cgroupLimitBytes();
|
| 38 |
const RAM_BYTES = CGROUP_BYTES || os.totalmem() || (16 * 1024 * MB);
|
| 39 |
const CHUNK_SIZE = 256 * 1024;
|
| 40 |
+
const HOT_HEAD = 32 * MB;
|
| 41 |
+
const HOT_TAIL = 12 * MB;
|
| 42 |
+
const STREAM_WINDOW = 12 * MB;
|
| 43 |
const PROBE_HEAD = 4 * MB;
|
| 44 |
+
const BOT_MAX = 100;
|
| 45 |
const PIPE_MS = 30000;
|
| 46 |
const PIPE_MAX_MS = 3 * 60 * 60 * 1000;
|
| 47 |
+
const RANGE_LOOKAHEAD = 16;
|
| 48 |
+
const WARM_AHEAD = 16;
|
| 49 |
+
const WARM_BUDGET_BYTES = 128 * MB;
|
| 50 |
let warmBytesInFlight = 0;
|
| 51 |
+
const WARM_BATCH = Math.max(2, Math.min(4, CPU_N * 2));
|
| 52 |
+
const IP_STREAM_MAX = 100000;
|
| 53 |
+
const IP_TITLE_MAX = 50000;
|
| 54 |
+
const UID_STREAM_MAX = 50000;
|
| 55 |
+
const UID_TITLE_MAX = 25000;
|
| 56 |
+
const TITLE_PIPE_MAX = 100000;
|
| 57 |
+
const GLOBAL_PIPE_MAX = 100000;
|
| 58 |
const DISK_SLICE_DIR = "/tmp/dlk_slice";
|
| 59 |
const DISK_MAX_BYTES = 24 * 1024 * 1024 * 1024;
|
| 60 |
const DISK_FREE_MIN_BYTES = 4 * 1024 * 1024 * 1024;
|
| 61 |
+
const HOT_BYTES_MAX = Math.min(3072 * MB, Math.max(1024 * MB, Math.floor(RAM_BYTES * 0.2)));
|
| 62 |
const BODY_MAX = 262144;
|
| 63 |
const FILE_TTL = 20 * 60 * 1000;
|
| 64 |
const LVL_TTL = 60000;
|
|
|
|
| 513 |
const key = ipNet(ip) + ":" + slot;
|
| 514 |
const n = (rateMap.get(key) || 0) + 1;
|
| 515 |
rateMap.set(key, n);
|
| 516 |
+
return n > 200000;
|
| 517 |
}
|
| 518 |
|
| 519 |
function slotOver(key, max) {
|
|
|
|
| 526 |
|
| 527 |
function mintLimited(ip) {
|
| 528 |
const s = String(ip || "0");
|
| 529 |
+
return slotOver("mint:" + s, 100000) || slotOver("mintn:" + ipNet(s), 500000);
|
| 530 |
}
|
| 531 |
|
| 532 |
function mintBlocked(ip) {
|
| 533 |
const slot = Math.floor(Date.now() / 60000);
|
| 534 |
+
return (rateMap.get("badm:" + String(ip || "0") + ":" + slot) || 0) > 10000;
|
| 535 |
}
|
| 536 |
|
| 537 |
function mintFailed(ip) {
|
| 538 |
+
return slotOver("badm:" + String(ip || "0"), 10000);
|
| 539 |
}
|
| 540 |
|
| 541 |
function isBlogOrigin(o) {
|
|
|
|
| 886 |
floodSleepThreshold: 2,
|
| 887 |
requestRetries: 3,
|
| 888 |
downloadRetries: 3,
|
| 889 |
+
maxConcurrentDownloads: 32,
|
| 890 |
+
downloadPool: { inflightPerDc: 8, maxSessions: 6, sessions: 6, requestDeadlineMs: 28000 }
|
| 891 |
});
|
| 892 |
client.setLogLevel("error");
|
| 893 |
await client.start({ botAuthToken: token });
|
|
|
|
| 3409 |
requestTimeout: 0,
|
| 3410 |
connectionsCheckingInterval: 10000
|
| 3411 |
}, onReq);
|
| 3412 |
+
srv.maxConnections = 100000;
|
| 3413 |
srv.timeout = 0;
|
| 3414 |
srv.on("clientError", (err, sock) => {
|
| 3415 |
try {
|