Skip to content

Commit

Permalink
🚀 feat: add multiprocessing for miner
Browse files Browse the repository at this point in the history
  • Loading branch information
fedosov committed Apr 28, 2023
1 parent ea54c4c commit 53bf295
Show file tree
Hide file tree
Showing 10 changed files with 1,293 additions and 63 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ corepack enable
pnpm i
```

Run miner:
Config miner: check file `ecosystem.config.js` to set params and multiprocessing.

Run/stop miner:
```bash
pnpm miner --interval 100
pnpm start
pnpm stop
pnpm restart
```
- `--interval 100` is the amount of time in milliseconds between the last and the next one objects being sent towards the Node. Depending on how much threads are you mining with, reduce the interval until you reach desired proc load.

Make sure you can see your node in the [list](https://telemetry.3dpass.org/). Use this [tutorial](https://3dpass.org/mainnet.html#mining_docker) for more details.

Expand Down
19 changes: 19 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
apps: [
{
name: "miner",
script: "miner.js",
args: "--host 127.0.0.1 --port 9833 --interval 10",
instances: 4,
autorestart: true,
watch: false,
max_memory_restart: "1G",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
},
},
],
};
2 changes: 1 addition & 1 deletion miner-libs/Perlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ class Perlin {
}
}

export default Perlin;
module.exports = Perlin;
14 changes: 7 additions & 7 deletions miner-libs/rock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* @copyright https://github.com:Erkaman/gl-rock
*/

import vec3 from "gl-vec3";
import seedRandom from "seed-random";
import * as THREE from "three";
const vec3 = require("gl-vec3");
const seedRandom = require("seed-random");
const THREE = require("three");

import Perlin from "./Perlin.js";
import createSphere from "./sphere.js";
import scrape from "./scrape.js";
const Perlin = require("./Perlin.js");
const createSphere = require("./sphere.js");
const scrape = require("./scrape.js");

let adjacentVertices = null;

Expand Down Expand Up @@ -126,4 +126,4 @@ const Rock = function (rockObj) {
return rock;
};

export default Rock;
module.exports = Rock;
4 changes: 2 additions & 2 deletions miner-libs/rock_obj.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @copyright https://github.com:Erkaman/gl-rock
*/
import randomArray from "random-array";
const randomArray = require("random-array");

/*
RockObj contains all the parameters that are used when generating a rock.
Expand Down Expand Up @@ -115,4 +115,4 @@ const SCALE_MIN = +1.0;
const SCALE_MAX = +2.0;
const SCALE_VARY = +0.1;

export default RockObj;
module.exports = RockObj;
6 changes: 3 additions & 3 deletions miner-libs/scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @copyright https://github.com:Erkaman/gl-rock
*/

import Set from "es6-set";
import vec3 from "gl-vec3";
const Set = require("es6-set");
const vec3 = require("gl-vec3");

function getNeighbours(positions, cells) {
/*
Expand Down Expand Up @@ -128,7 +128,7 @@ const scrape = function (
}
};

export default {
module.exports = {
scrape,
getNeighbours,
};
2 changes: 1 addition & 1 deletion miner-libs/sphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ const createSphere = function (opt) {
return { vertices: vertices, cells: indexes, normals: normals };
};

export default createSphere;
module.exports = createSphere;
31 changes: 18 additions & 13 deletions miner.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import RockObj from "./miner-libs/rock_obj.js";
import Rock from "./miner-libs/rock.js";
import randomArray from "random-array";
import * as THREE from "three";
import { OBJExporter } from "three/examples/jsm/exporters/OBJExporter.js";
import axios from "axios";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import fs from "fs";
const RockObj = require("./miner-libs/rock_obj.js");
const Rock = require("./miner-libs/rock.js");
const randomArray = require("random-array");
const THREE = require("three");
const OBJExporter = import("three/examples/jsm/exporters/OBJExporter.js");
const axios = require("axios");
const yargs = require("yargs");
const { hideBin } = require("yargs/helpers");
const fs = require("fs");

const argv = yargs(hideBin(process.argv)).argv;
const interval = argv.interval || 1000;
const host = argv.host || "localhost";
const host = argv.host || "127.0.0.1";
const port = argv.port || "9933";
const do_save = argv.save || false;
const apiUrl = `http://${host}:${port}`;
const filename = "rock.obj";

mining(do_save);
let exporterModule;
let exporter;

void mining(do_save);

async function mining(do_save) {
exporterModule = await OBJExporter;
exporter = new exporterModule.OBJExporter();

function mining(do_save) {
const rock = create_rock();
const obj_file = create_obj_file(rock);
if (do_save) {
Expand Down Expand Up @@ -56,7 +62,6 @@ function create_obj_file(rock) {
const mesh = new THREE.Mesh(rock.geometry);
scene.add(mesh);

const exporter = new OBJExporter();
return exporter.parse(scene);
}

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"version": "1.0.0",
"repository": "https://github.com/3Dpass/pass3d",
"license": "MIT",
"type": "module",
"type": "commonjs",
"scripts": {
"preinstall": "npx only-allow pnpm",
"miner": "node miner.js"
"start": "pm2 start",
"stop": "pm2 stop all && pm2 del all",
"restart": "pm2 restart all"
},
"devDependencies": {
"prettier": "2.8.8"
Expand All @@ -17,6 +19,7 @@
"axios": "1.4.0",
"es6-set": "0.1.6",
"gl-vec3": "1.1.3",
"pm2": "5.3.0",
"random-array": "0.0.2",
"seed-random": "2.2.0",
"three": "0.152.1",
Expand Down
Loading

0 comments on commit 53bf295

Please sign in to comment.