os#setPriority JavaScript Examples
The following examples show how to use
os#setPriority.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From NIM-Pools-Hub-Miner with GNU General Public License v3.0 | 4 votes |
startMining = async (gpu = false) => {
const priority = Object.entries(constants.priority)[
store.state.settings.cpuPriority
];
try {
setPriority(priority[1]);
} catch (error) {
console.error("Set CPU Priority Failed: ", error);
}
const deviceName = store.state.settings.deviceName;
const maxThreads = store.state.settings.cpuThreads;
const userAddress = store.state.settings.address;
const poolHost = store.state.settings.host;
const poolPort = store.state.settings.port;
console.log("GPU: " + gpu);
Nimiq.Log.i(TAG, `- network = main`);
Nimiq.Log.i(TAG, `- no. of threads = ${maxThreads}`);
Nimiq.Log.i(TAG, `- pool server = ${poolHost}:${poolPort}`);
Nimiq.Log.i(TAG, `- address = ${userAddress}`);
Nimiq.Log.i(TAG, `- device name = ${deviceName}`);
if (Nimiq.Log.instance.level === 3) {
Nimiq.Log.w(TAG, `Debug mode has been enabled.`);
}
const hashrate = gpu ? 200 : 50; // 100 kH/s by default
const desiredSps = 5;
const startDifficulty = (1e3 * hashrate * desiredSps) / (1 << 16);
const minerVersion = `NPH Miner ${gpu ? "GPU" : "CPU"} ${app.getVersion()}`;
const userAgent = `${minerVersion} (${Nimiq.PlatformUtils.userAgentString})`;
const deviceData = {
deviceName,
startDifficulty,
minerVersion,
userAgent,
};
if (!gpu) {
$.miner = new SushiPoolCpuMiner(userAddress, deviceData, maxThreads);
$.miner.on("hashrate-changed", async (hashrates) => {
const totalHashrate = hashrates.reduce((a, b) => a + b, 0);
const temp = await cpuTemperature();
Nimiq.Log.i(TAG, `Hashrate: ${humanHashes(totalHashrate)}`);
Nimiq.Log.i(TAG, `CPU Temp: ${temp.main}`);
try {
store.dispatch("setCpuHashrate", humanHashes(totalHashrate));
} catch (e) {
console.log(e);
}
});
$.miner.connect(poolHost, poolPort);
$.miner.on("share", (nonce) => {
Nimiq.Log.i(TAG, `Found share. Nonce: ${nonce}`);
});
$.miner.on("pool-disconnected", function () {
Nimiq.Log.w(TAG, `Lost connection with ${poolHost}.`);
});
$.miner.on("pool-balance", (balances) => {
store.dispatch("setPoolBalance", balances);
});
} else {
const vendor = (await graphics()).controllers[0].vendor;
if (!vendor.includes("Advanced Micro Devices") && !vendor.includes("NVIDIA")) {
mainWindow.webContents.send("no-gpu-alert");
}
const type = vendor.includes("NVIDIA") ? "cuda" : "opencl";
console.log(`GPU Type: ${type}`);
const argv = {
memory: [store.state.settings.gpuMemory],
threads: [store.state.settings.gpuThreads],
cache: [store.state.settings.gpuCache],
memoryTradeoff: [store.state.settings.gpuMemoryTradeoff],
jobs: [store.state.settings.gpuJobs],
};
const deviceOptions = getDeviceOptions(argv);
$.nativeMiner = new NativeMiner(type, deviceOptions);
$.nativeMiner.on("hashrate-changed", (hashrates) => {
const totalHashrate = hashrates.reduce((a, v) => a + (v || 0), 0);
Nimiq.Log.i(
TAG,
`Hashrate: ${humanHashes(totalHashrate)} | ${hashrates
.map((hr, idx) => `GPU${idx}: ${humanHashes(hr)}`)
.filter((hr) => hr)
.join(" | ")}`
);
try {
/* mainWindow.webContents.send(
"hashrate-update",
humanHashes(totalHashrate)
); */
store.dispatch("setGpuHashrate", humanHashes(totalHashrate));
} catch (e) { }
});
const deviceId = DumbPoolMiner.generateDeviceId();
Nimiq.Log.i(TAG, `- device id = ${deviceId}`);
$.minerGPU = new DumbPoolMiner(
$.nativeMiner,
Nimiq.Address.fromUserFriendlyAddress(userAddress),
deviceId,
deviceData
);
$.minerGPU.connect(poolHost, poolPort);
$.minerGPU.on("share", (nonce) => {
Nimiq.Log.i(TAG, `Found share. Nonce: ${nonce}`);
});
$.minerGPU.on("pool-disconnected", function () {
Nimiq.Log.w(TAG, `Lost connection with ${poolHost}.`);
});
$.minerGPU.on("pool-balance", (balances) => {
store.dispatch("setPoolBalance", balances);
});
}
}