dcp-worker 3.3.13 → 3.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitlab-ci.yml CHANGED
@@ -107,6 +107,28 @@ check:
107
107
  - node_modules/
108
108
  policy: pull
109
109
 
110
+ test:
111
+ variables:
112
+ DCP_CLIENT_ALLOW_INSECURE_CONFIGURATION: true
113
+ stage: test
114
+ script:
115
+ - npx peter -v --junit test_report.xml tests/
116
+ cache:
117
+ - key:
118
+ prefix: node-modules
119
+ files:
120
+ - package-lock.json
121
+ paths:
122
+ - node_modules/
123
+ policy: pull
124
+ artifacts:
125
+ expire_in: 1 day
126
+ when: always
127
+ paths:
128
+ - test_report.xml
129
+ reports:
130
+ junit: test_report.xml
131
+
110
132
  publish_docs:
111
133
  stage: deploy
112
134
  needs:
package/bin/dcp-worker CHANGED
@@ -94,9 +94,9 @@ function parseCliArgs()
94
94
  describe: 'Number of CPU and GPU cores to work with: the format is 7,1 (or just 7) for 7 CPU cores and 1 GPU',
95
95
  type: 'string',
96
96
  },
97
- density: {
98
- alias: 'd',
99
- describe: 'default proportion of CPU,GPU to use when cores not specified',
97
+ utilization: {
98
+ alias: 'u',
99
+ describe: 'default proportion of CPU,GPU to utilize: the format is -u 0.8,0.75 for 80% CPU and 75% GPU utilization',
100
100
  type: 'string',
101
101
  },
102
102
  maxSandboxes: {
@@ -145,7 +145,6 @@ function parseCliArgs()
145
145
  describe: 'Restrict worker to a specific job (use N times for N jobs)',
146
146
  type: 'array',
147
147
  },
148
-
149
148
  join: {
150
149
  alias: 'g',
151
150
  hidden: true,
@@ -193,7 +192,8 @@ function parseCliArgs()
193
192
 
194
193
  showConfig: {
195
194
  hide: false,
196
- describe: 'Show merged configuration node (eg worker)',
195
+ describe: 'Show merged configuration node (e.g., --showConfig worker)',
196
+ type: 'string',
197
197
  },
198
198
 
199
199
  logfile: {
@@ -255,18 +255,6 @@ function parseCliArgs()
255
255
  .wrap(process.stdout.columns || 80)
256
256
  .argv;
257
257
 
258
- if (cliArgs.showConfig)
259
- {
260
- console.log(eval('dcpConfig.' + cliArgs.showConfig));
261
- process.exit();
262
- }
263
-
264
- if (cliArgs.dumpConfig)
265
- {
266
- console.log(JSON.stringify(require('dcp/dcp-config'), null, 2));
267
- processExit(0);
268
- }
269
-
270
258
  return cliArgs;
271
259
  }
272
260
 
@@ -370,7 +358,7 @@ async function main()
370
358
  *
371
359
  * It is important to never disable leavePublicGroup as a side effect of any other operation, or
372
360
  * slight configuration errors could have large security impacts.
373
- */
361
+ z */
374
362
  const dcpWorkerOptions = dcpConfig.worker;
375
363
  const forceOptions = {
376
364
  paymentAddress,
@@ -412,6 +400,8 @@ async function main()
412
400
 
413
401
  if (cliArgs.jobId)
414
402
  {
403
+ if (dcpWorkerOptions.jobAddresses === false || dcpWorkerOptions.jobAddresses === undefined)
404
+ dcpWorkerOptions.jobAddresses = [];
415
405
  dcpWorkerOptions.jobAddresses.push(...cliArgs.jobId);
416
406
  dcpWorkerOptions.priorityOnly = true;
417
407
  }
@@ -427,14 +417,26 @@ async function main()
427
417
  if (cliArgs.watchdogInterval)
428
418
  dcpWorkerOptions.watchdogInterval = cliArgs.watchdogInterval;
429
419
 
430
- if (dcpConfig.bannedGPUs)
420
+ if (cliArgs.showConfig)
431
421
  {
432
- for (let prop of dcpConfig.bannedGPUs)
422
+ console.log(eval('dcpConfig.' + cliArgs.showConfig));
423
+ process.exit();
424
+ }
425
+
426
+ if (cliArgs.dumpConfig)
427
+ {
428
+ console.log(JSON.stringify(require('dcp/dcp-config'), null, 2));
429
+ process.exit();
430
+ }
431
+
432
+ if (dcpConfig.worker?.bannedGPUs)
433
+ {
434
+ for (let prop in dcpConfig.worker.bannedGPUs)
433
435
  {
434
436
  if (!bannedGPUs[prop])
435
- bannedGPUs[prop] = dcpConfig.bannedGPUs[prop];
437
+ bannedGPUs[prop] = dcpConfig.worker?.bannedGPUs[prop];
436
438
  else
437
- bannedGPUs[prop] = new RegExp(`(${dcpConfig.bannedGPUs[prop].source})|(${bannedGPUs[prop].source})`);
439
+ bannedGPUs[prop] = new RegExp(`(${dcpConfig.worker?.bannedGPUs[prop].source})|(${bannedGPUs[prop].source})`);
438
440
  }
439
441
  }
440
442
 
@@ -449,6 +451,7 @@ async function main()
449
451
  nascentWorker.on('warning', (...payload) => console.warn (...payload));
450
452
  nascentWorker.on('stop', () => { console.log('Worker is stopping') });
451
453
  nascentWorker.on('end', () => { logClosing('log', 'Worker has stopped') });
454
+ nascentWorker.on('job', job => console.log(` . Job: ${job.name} ${job.address.slice(0,8)} ${job.description || ''} ${job.link || ''}`));
452
455
 
453
456
  // Display clean diagnostic when not debugging and env var
454
457
  // DCP_SUPERVISOR_DEBUG_DISPLAY_MAX_INFO isn't set.
@@ -521,10 +524,10 @@ async function main()
521
524
  bannerLog(' . Falling back on global group when preferred groups have no work');
522
525
  if (dcpWorkerOptions.leavePublicGroup)
523
526
  bannerLog(' . Leaving the global compute group');
524
- if (dcpWorkerOptions.cores)
525
- bannerLog(` . Configured Cores: ${dcpWorkerOptions.cores.cpu},${dcpWorkerOptions.cores.gpu}`);
526
- if (typeof dcpWorkerOptions.maxSandboxes !== 'undefined')
527
- bannerLog(` . Maximum Sandboxes: ${dcpWorkerOptions.maxSandboxes}`);
527
+ bannerLog(` . Configured Cores: { cpu: ${dcpWorkerOptions.cores.cpu}, gpu: ${dcpWorkerOptions.cores.gpu} }`);;
528
+ bannerLog(` . Utilization: { cpu: ${dcpWorkerOptions.utilization.cpu}, gpu: ${dcpWorkerOptions.utilization.gpu} }`);
529
+ bannerLog(` . Effective Cores: { cpu: ${dcpWorkerOptions.utilization.cpu * dcpWorkerOptions.cores.cpu}, gpu: ${dcpWorkerOptions.utilization.gpu * dcpWorkerOptions.cores.gpu} }`);
530
+ bannerLog(` . Maximum Sandboxes: ${dcpWorkerOptions.maxSandboxes}`);
528
531
  if (cliArgs.verbose)
529
532
  bannerLog(` + Verbosity level: ${cliArgs.verbose}`);
530
533
  if (telnetd.hasOwnProperty('port'))
@@ -599,8 +602,7 @@ async function main()
599
602
  }
600
603
 
601
604
  /**
602
- * Process the cores and maxSandboxes cli arguments.
603
- * Also processes density, but that isn't currently used and may be deprecated in the future.
605
+ * Process the cores, utilization and maxSandboxes cli arguments.
604
606
  *
605
607
  * cliArgs.cores is the core count of the hardware to use.
606
608
  * It can be specified with only the cpu or gpu component, or both.
@@ -608,35 +610,35 @@ async function main()
608
610
  * E.g. -c 2,1 => cores = { cpu: 2, gpu: 1 }
609
611
  * -c 10 => cores = { cpu: 10, gpu: <default> }
610
612
  * -c ,10 => cores = { cpu: <default>, gpu: 10 }
613
+ * -u 0.80,0.75 => utilization = { cpu: 0.80, gpu: 0.75 }
611
614
  * -m 5 => maxSandboxes = 5
612
- * default maxSandboxes := Math.max( 1, Math.round((System RAM) / 2.5GB) );
613
615
  */
614
616
  function processCoresAndMaxSandboxes (dcpWorkerOptions, cliArgs)
615
617
  {
616
- const DCPWorker = require('dcp/worker').Worker;
617
- const defaultTargets = {
618
- density: dcpWorkerOptions.defaultCoreDensity || { cpu: 0, gpu: 0 }, /* 0,0 => user specified corrupt conf */
619
- cores: DCPWorker.defaultCores(dcpWorkerOptions),
620
- };
618
+ if (typeof cliArgs['maxSandboxes'] !== 'undefined')
619
+ dcpWorkerOptions.maxSandboxes = Number(cliArgs['maxSandboxes']);
621
620
 
622
621
  const parseArg = (which) => {
623
- if (!cliArgs[which])
624
- dcpWorkerOptions[which] = defaultTargets[which];
625
- else
622
+ if (cliArgs[which])
626
623
  {
624
+ dcpWorkerOptions[which] = {};
627
625
  const [cpu, gpu] = cliArgs[which].split(',');
628
- dcpWorkerOptions[which] = { cpu: Number(cpu || defaultTargets[which].cpu),
629
- gpu: Number(gpu || defaultTargets[which].gpu) };
626
+ if (cpu?.length > 0)
627
+ dcpWorkerOptions[which].cpu = Number(cpu);
628
+ if (gpu?.length > 0)
629
+ dcpWorkerOptions[which].gpu = Number(gpu);
630
630
  }
631
631
  };
632
632
 
633
- parseArg('density');
633
+ parseArg('utilization');
634
634
  parseArg('cores');
635
635
 
636
- if (typeof cliArgs['maxSandboxes'] !== 'undefined')
637
- dcpWorkerOptions.maxSandboxes = Number(cliArgs['maxSandboxes']);
638
- debugging() && console.debug(`dcp-worker: cores = { ${dcpWorkerOptions.cores.cpu}, ${dcpWorkerOptions.cores.gpu} }`);
639
- debugging() && console.debug('dcp-worker: core density =', dcpWorkerOptions.density);
636
+ if (debugging())
637
+ {
638
+ console.debug(`dcp-worker: cores = { cpu: ${dcpWorkerOptions.cores.cpu}, gpu: ${dcpWorkerOptions.cores.gpu} }`);
639
+ console.debug('dcp-worker: utilization =', dcpWorkerOptions.utilization);
640
+ console.debug('dcp-worker: maxSandboxes =', dcpWorkerOptions.maxSandboxes);
641
+ }
640
642
  }
641
643
 
642
644
  /**
@@ -40,6 +40,9 @@
40
40
  'in': 0, /* DCC per megabyte of inbound network traffic */
41
41
  'out': 0, /* DCC per megabyte of outbound network traffic */
42
42
  },
43
+ bannedGPUs: {
44
+ description: /D3D.*version\s[0-2][0-9]/
45
+ },
43
46
 
44
47
  /* Extra Compute Groups this worker can participate in. Join credentials are supplied by
45
48
  * Distributive and/or local IT staff at site-licensed locations.
@@ -1,2 +1,2 @@
1
- 9911ec21ecad5d6fa18b1663715bed5b
1
+ 271fe64e9b77126815dbb9aff6a3412f
2
2
  ### DO NOT MODIFY THIS FILE!!! ###
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcp-worker",
3
- "version": "3.3.13",
3
+ "version": "3.3.15",
4
4
  "description": "Node.js Worker for Distributive Compute Platform",
5
5
  "main": "bin/dcp-worker",
6
6
  "keywords": [
@@ -40,7 +40,7 @@
40
40
  "blessed": "^0.1.81",
41
41
  "blessed-contrib": "4.11.0",
42
42
  "chalk": "^4.1.0",
43
- "dcp-client": "4.4.12",
43
+ "dcp-client": "^4.4.18",
44
44
  "kvin": "^1.2.7",
45
45
  "posix-getopt": "^1.2.1",
46
46
  "semver": "^7.3.8",
@@ -53,7 +53,8 @@
53
53
  "devDependencies": {
54
54
  "@distributive/eslint-config": "2.1.4",
55
55
  "@trunkio/launcher": "1.2.7",
56
- "eslint": "8.56.0"
56
+ "eslint": "8.56.0",
57
+ "peter": "2.4.7"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "node-eventlog": "https://gitpkg.now.sh/Distributive-Network/node-eventlog/package?dcp/0.0.1"
@@ -0,0 +1,60 @@
1
+ #! /usr/bin/env node
2
+
3
+ /**
4
+ * @file worker-with-no-options.simple
5
+ *
6
+ * @author Nazila Akhavan <nazila@distributive.network>
7
+ * @date Aug 2024
8
+ *
9
+ * peter-timeout: 60
10
+ */
11
+ 'use strict';
12
+
13
+ const { tmpdir } =require('node:os');
14
+ const { spawnSync } = require('node:child_process');
15
+ const { mkdtempSync, rmSync, existsSync, writeFileSync } = require('node:fs');
16
+ const { join, parse, basename } = require('node:path');
17
+ const { strictEqual, deepEqual } = require('node:assert');
18
+
19
+ const filename = parse(basename(__filename)).name;
20
+ const tempd = mkdtempSync(join(tmpdir(), `${filename}-`));
21
+
22
+ process.on('exit', () => { existsSync(tempd) && rmSync(tempd, { recursive: true }) });
23
+ process.chdir(__dirname);
24
+
25
+ async function main()
26
+ {
27
+ const { Keystore } = require('dcp/wallet');
28
+ const ks = await new Keystore(null);
29
+ const id = await new Keystore(null);
30
+
31
+ writeFileSync(`${tempd}/default.keystore`, JSON.stringify(ks.toJSON()), { encoding: 'utf-8' });
32
+ writeFileSync(`${tempd}/id.keystore`, JSON.stringify(id.toJSON()), { encoding: 'utf-8' });
33
+ const res = spawnSync(
34
+ '../bin/dcp-worker', ['--dumpConfig'],
35
+ {
36
+ encoding: 'utf-8',
37
+ env: {
38
+ ...process.env,
39
+ DCP_RESOURCE_DIR: tempd
40
+ }
41
+ }
42
+ );
43
+
44
+ const confObj = JSON.parse(res.stdout);
45
+ strictEqual(confObj.worker.paymentAddress, ks.address.valueOf(), `${confObj.worker.paymentAddress} payment address is not correct`);
46
+ strictEqual(confObj.worker.leavePublicGroup, undefined, `leaveComputeGroup is ${confObj.worker.leavePublicGroup}`);
47
+ deepEqual(confObj.worker.allowOrigins.any, [], `allowOrigins should be empty. It includes ${confObj.worker.allowOrigins.any}`);
48
+ deepEqual(confObj.worker.cores.cpu, undefined, `Mismatch in cores! cpu: ${confObj.worker.cores.cpu}`);
49
+ deepEqual(confObj.worker.cores.gpu, undefined, `Mismatch in cores! gpu: ${confObj.worker.cores.gpu}`);
50
+ deepEqual(confObj.worker.utilization, { cpu: 1, gpu: 0.75 }, `Mismatch in utilization! cpu: ${confObj.worker.utilization.cpu}, gpu: ${confObj.worker.utilization.gpu}`);
51
+ deepEqual(confObj.worker.computeGroups, [], `computeGroups should be an empty array it includes ${confObj.worker.computeGroups}`);
52
+ deepEqual(confObj.worker.maxSandboxes, undefined, `Mismatch! maxSandboxes:${confObj.worker.maxSandboxes}`);
53
+ deepEqual(confObj.worker.jobAddresses, undefined, `jobAddresses should be false but it is ${confObj.worker.jobAddresses}`);
54
+
55
+ console.log('Done.');
56
+ }
57
+
58
+ require('dcp-client')
59
+ .init()
60
+ .then(main);
@@ -0,0 +1,68 @@
1
+ #! /usr/bin/env node
2
+
3
+ /**
4
+ * @file worker-with-options.simple
5
+ *
6
+ * @author Nazila Akhavan <nazila@distributive.network>
7
+ * @date Aug 2024
8
+ *
9
+ * peter-timeout: 60
10
+ */
11
+ 'use strict';
12
+
13
+ const { tmpdir } =require('node:os');
14
+ const { spawnSync } = require('node:child_process');
15
+ const { mkdtempSync, rmSync, existsSync, writeFileSync } = require('node:fs');
16
+ const { join, parse, basename } = require('node:path');
17
+ const { strictEqual, deepEqual } = require('node:assert');
18
+
19
+ const filename = parse(basename(__filename)).name;
20
+ const tempd = mkdtempSync(join(tmpdir(), `${filename}-`));
21
+
22
+ process.on('exit', () => { existsSync(tempd) && rmSync(tempd, { recursive: true }) });
23
+ process.chdir(__dirname);
24
+
25
+ async function main()
26
+ {
27
+ const { Keystore } = require('dcp/wallet');
28
+ const ks = await new Keystore(null);
29
+ const id = await new Keystore(null);
30
+
31
+ writeFileSync(`${tempd}/default.keystore`, JSON.stringify(ks.toJSON()), { encoding: 'utf-8' });
32
+ writeFileSync(`${tempd}/id.keystore`, JSON.stringify(id.toJSON()), { encoding: 'utf-8' });
33
+ const res = spawnSync(
34
+ '../bin/dcp-worker', [
35
+ '--paymentAddress', '0x9fd0909Bd93f7bad915726C3AB499391384b8b4b',
36
+ '--leavePublicGroup',
37
+ '--allowedOrigins', 'test-url',
38
+ '--cores', '3,1',
39
+ '--utilization', '0.1,0.5',
40
+ '--maxSandboxes', '5',
41
+ '--job-id', '09fd0909Bd93f7bad915726C3AB4',
42
+ '--join', `joinKey1,joinHash1`, '-g', 'joinKey2,joinHash2',
43
+ '--dumpConfig' ],
44
+ {
45
+ encoding: 'utf-8',
46
+ env: {
47
+ ...process.env,
48
+ DCP_RESOURCE_DIR: tempd
49
+ }
50
+ }
51
+ );
52
+
53
+ const confObj = JSON.parse(res.stdout);
54
+ strictEqual(confObj.worker.paymentAddress, '0x9fd0909Bd93f7bad915726C3AB499391384b8b4b', `${confObj.worker.paymentAddress} payment address is not corrrect`);
55
+ strictEqual(confObj.worker.leavePublicGroup, true, `leaveComputeGroup is ${confObj.worker.leavePublicGroup}`);
56
+ deepEqual(confObj.worker.allowOrigins.any.includes('test-url'), true, `allowOrigins only includes ${confObj.worker.allowOrigins.any}!`);
57
+ deepEqual(confObj.worker.cores, { cpu: 3, gpu: 1 }, `Mismatch in cores! cpu: ${confObj.worker.cores.cpu}, gpu: ${confObj.worker.cores.gpu}`);
58
+ deepEqual(confObj.worker.utilization, { cpu: 0.1, gpu: 0.5 }, `Mismatch in utilization! cpu: ${confObj.worker.utilization.cpu}, gpu: ${confObj.worker.utilization.gpu}`);
59
+ deepEqual(confObj.worker.computeGroups, [{ joinKey: 'joinKey1', joinSecret: 'joinHash1' }, { joinKey: 'joinKey2', joinSecret: 'joinHash2' }], 'Mismatch in computeGroups')
60
+ deepEqual(confObj.worker.maxSandboxes, 5, `Mismatch! maxSandboxes:${confObj.worker.maxSandboxes}`);
61
+ deepEqual(confObj.worker.jobAddresses, ['09fd0909Bd93f7bad915726C3AB4'], `Mismatch in job addresses! jobAddresses:${confObj.worker.jobAddresses}`);
62
+
63
+ console.log('Done.');
64
+ }
65
+
66
+ require('dcp-client')
67
+ .init()
68
+ .then(main);