dcp-web-worker-template

by DCP

HTML

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <script src="https://scheduler.distributed.computer/dcp-client/dcp-client.js"></script>
  <script type="module">
    //
    // Logging function
    //
    const consoleEl = document.querySelector("#workerConsole");
    const log = (msg) => {
      const ts = new Date().toLocaleTimeString();
      consoleEl.value += `[${ts}] ${msg}\n\n`;
      consoleEl.scrollTop = consoleEl.scrollHeight;
    };

    //
    // Set DCP identity for this worker
    //
    const id = await new dcp.wallet.Keystore(
      "0x5356d59ec41a45672e4be75a8761e1721f7b48941226f2775722907238f805be","" // web-worker-demo-id
    );
    await dcp.identity.set(id);

    //
    // Configure Worker
    //
    const worker = new dcp.worker.DistributiveWorker({
      
      // Set the DCP Bank account where compute credits earned from work are deposited
      paymentAddress: new dcp.wallet.Address(
        "0xd9e31076e34c34da0d902eb01b1e7ae622791941" // or (await dcp.wallet.get()).address
      ),
      /*
      // Configure whether this worker remains part of the public compute group or opts out
      leavePublicGroup: true,

      // Set the compute group(s) the worker will join
      computeGroups: [
        { joinKey: "demo", joinSecret: "dcp" },
      ],
      */
      // Restrict the worker to specific job IDs, e.g. ["jeHgigTXPURl6xMgUz9oNw", "..."]
      jobIds: false,

      // Set number CPU and GPU cores available to use
      cores: { cpu: 4, gpu: 1 },

      // Set target % utilization for cpu and gpu
      utilization: { cpu: 1, gpu: 1 },

      // Set the maximum number of concurrent sandboxes that can execute job slices
      maxSandboxes: 4,

      // Set minimum-wage vector defining the lowest-paying slices it will accept
      minimumWage: {
        "CPU":  0.0060 /1000,      //   Compute Credits per CPU-second
        "GPU":  0.0241 /1000,      //   Compute...