Running a dht node is as simple as installing the DHT cli.
npm i -g @hyperswarm/cli
const Corestore = require('corestore') | |
const SwarmNetworker = require('corestore-swarm-networking') | |
const store = new Corestore('./path-1') | |
store.ready(function () { | |
const swarm = new SwarmNetworker(store) | |
const feed = store.default() | |
swarm.listen() |
This showcases how you can use shared-structs over an SharedArrayBuffer, to share complex data structures between worker_threads in Node.js
The main.js example starts a worker and passes a shared struct to it.
The worker will periodically update the struct with an incrementing tick and a random number
const stream = require('stream') | |
const cache = new Map() // you might wanna use an lru here | |
function createCacheStream (url) { | |
const buf = [] | |
return stream.Transform({ | |
transform: function (data, enc, cb) { | |
buffer.push(data) | |
cb(null, data) | |
}, |
#include <dlfcn.h> | |
static int mallocs_active = 0; | |
void *malloc(size_t size) { | |
void * (*real_malloc)(size_t); | |
real_malloc = dlsym(RTLD_NEXT, "malloc"); | |
mallocs_active++; | |
void *ptr = real_malloc(size); |
start() | |
async function start () { | |
const promises = [ | |
new Promise((resolve, reject) => setTimeout(reject, 1000)), | |
Promise.reject(), | |
Promise.reject() | |
] | |
for (const a of promises) { |
# create a tinycorelinux fs with custom .tcz packages | |
# prerequisites: apt-get install squashfs-tools, npm i nugget -g | |
# dl release + packages (add your packages here) | |
nugget http://tinycorelinux.net/6.x/x86_64/release/CorePure64-6.3.iso http://tinycorelinux.net/6.x/x86_64/tcz/{pkg-config,make,gcc,gcc_base-dev,gcc_libs-dev,gcc_libs,glibc_base-dev,linux-3.16.2_api_headers,fuse}.tcz -c | |
# to support compiling addons | |
unsquashfs -f pkg-config.tcz | |
unsquashfs -f make.tcz | |
unsquashfs -f gcc.tcz |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<video src="custom://u" controls></video> | |
<!-- <video src="http://localhost:9999" controls></video> --> | |
</body> |
╔════════════════════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╤═════════════════════════╗ | |
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║ | |
╟────────────────────────────────────────────────────────┼─────────┼───────────────────┼───────────┼─────────────────────────╢ | |
║ crypto sha256 (prealloc) │ 10000 │ 370321.25 op/sec │ ± 4.65 % │ ║ | |
║ crypto sha512 (prealloc) │ 1000 │ 382075.76 op/sec │ ± 0.94 % │ + 3.17 % ║ | |
║ crypto blake2b512 (prealloc) │ 1000 │ 401530.47 op/sec │ ± 0.98 % │ + 8.43 % ║ | |
║ crypto sha256 (no prealloc) │ 1000 │ 453419.74 op/sec │ ± 0.80 % │ + 22.44 % ║ | |
║ crypto sha512 (no prealloc) │ 1000 │ 460150.51 op/sec │ ± 0.69 % │ + 24.26 % ║ | |
║ crypto |
╔═════════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╤═════════════════════════╗ | |
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║ | |
╟─────────────────────────────────────────────┼─────────┼───────────────────┼───────────┼─────────────────────────╢ | |
║ crypto sha512 (prealloc) │ 10000 │ 340764.93 op/sec │ ± 6.40 % │ ║ | |
║ crypto sha256 (prealloc) │ 1000 │ 357872.79 op/sec │ ± 0.63 % │ + 5.02 % ║ | |
║ crypto blake2b512 (prealloc) │ 1000 │ 374023.05 op/sec │ ± 0.96 % │ + 9.76 % ║ | |
║ crypto sha256 (no prealloc) │ 10000 │ 416877.14 op/sec │ ± 8.05 % │ + 22.34 % ║ | |
║ crypto blake2b512 (no prealloc) │ 10000 │ 454022.65 op/sec │ ± 8.32 % │ + 33.24 % ║ | |
║ crypto sha512 (no prealloc) │ 1000 │ 468638.04 op/sec │ ± 0.72 % │ + 37.5 |