JOHN SILLVESTOR commited on
Commit
aeb996f
·
verified ·
1 Parent(s): cec3b7e

optimize streaming concurrency, bot pool, and buffer limits

Browse files
Files changed (1) hide show
  1. server.js +22 -22
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 = 24 * MB;
41
- const HOT_TAIL = 8 * MB;
42
- const STREAM_WINDOW = 8 * MB;
43
  const PROBE_HEAD = 4 * MB;
44
- const BOT_MAX = 60;
45
  const PIPE_MS = 30000;
46
  const PIPE_MAX_MS = 3 * 60 * 60 * 1000;
47
- const RANGE_LOOKAHEAD = 12;
48
- const WARM_AHEAD = 12;
49
- const WARM_BUDGET_BYTES = 64 * MB;
50
  let warmBytesInFlight = 0;
51
- const WARM_BATCH = Math.max(1, Math.min(2, CPU_N));
52
- const IP_STREAM_MAX = 25000;
53
- const IP_TITLE_MAX = 10000;
54
- const UID_STREAM_MAX = 2000;
55
- const UID_TITLE_MAX = 1000;
56
- const TITLE_PIPE_MAX = 50000;
57
- const GLOBAL_PIPE_MAX = 50000;
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(1536 * MB, Math.max(512 * MB, Math.floor(RAM_BYTES * 0.1)));
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 > 50000;
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, 25000) || slotOver("mintn:" + ipNet(s), 100000);
530
  }
531
 
532
  function mintBlocked(ip) {
533
  const slot = Math.floor(Date.now() / 60000);
534
- return (rateMap.get("badm:" + String(ip || "0") + ":" + slot) || 0) > 2000;
535
  }
536
 
537
  function mintFailed(ip) {
538
- return slotOver("badm:" + String(ip || "0"), 2000);
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: 16,
890
- downloadPool: { inflightPerDc: 4, maxSessions: 4, sessions: 4, requestDeadlineMs: 28000 }
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 = 30000;
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 {