Skip to content

Commit

Permalink
chore: yield chunks with delay
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Nov 24, 2023
1 parent b746d8d commit 07f755d
Show file tree
Hide file tree
Showing 568 changed files with 28,827 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DOCKER_IMAGE := node:20-alpine
DOCKER_RUN := docker run --rm -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp $(DOCKER_IMAGE)

all: perf

perf:
$(DOCKER_RUN) npm ci

clean:
rm -rf node_modules

.PHONY: all clean perf
109 changes: 109 additions & 0 deletions perf/impl/js-libp2p/v1.0-uint8arraylists-yield-chunks-nagle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { noise } from './noise/dist/src/index.js'
import { yamux } from './yamux/dist/src/index.js'
import { tcp } from './tcp/dist/src/index.js'
import { multiaddr } from '@multiformats/multiaddr'
import { createLibp2p } from './libp2p/dist/src/index.js'
import { perf } from '@libp2p/perf'
import { parseArgs } from 'node:util'

const argv = parseArgs({
options: {
'run-server': {
type: 'string',
default: 'false'
},
'server-address': {
type: 'string',
default: '127.0.0.1:8000'
},
transport: {
type: 'string',
default: 'tcp'
},
'upload-bytes': {
type: 'string',
default: '0'
},
'download-bytes': {
type: 'string',
default: '10000000000'
}
}
})

/**
* @param {boolean} runServer
* @param {string} serverIpAddress
* @param {string} transport
* @param {number} uploadBytes
* @param {number} downloadBytes
*/
export async function main (runServer, serverIpAddress, transport, uploadBytes, downloadBytes) {
const { host, port } = splitHostPort(serverIpAddress)

const config = {
transports: [
tcp()
],
streamMuxers: [
yamux()
],
connectionEncryption: [
noise()
],
connectionManager: {
minConnections: 0
},
services: {
perf: perf()
}
}

if (runServer) {
Object.assign(config, {
addresses: {
listen: [
// #TODO: right now we only support tcp
`/ip4/${host}/tcp/${port}`
]
}
})
}

const node = await createLibp2p(config)

await node.start()

if (!runServer) {
for await (const output of node.services.perf.measurePerformance(multiaddr(`/ip4/${host}/tcp/${port}`), uploadBytes, downloadBytes)) {
// eslint-disable-next-line no-console
console.log(JSON.stringify(output))
}

await node.stop()
}
}

/**
* @param {string} address
* @returns { host: string, port?: string }
*/
function splitHostPort (address) {
try {
const parts = address.split(':')
const host = parts[0]
const port = parts[1]
return {
host,
port
}
} catch (error) {
throw Error('Invalid server address')
}
}

main(argv.values['run-server'] === 'true', argv.values['server-address'], argv.values.transport, Number(argv.values['upload-bytes']), Number(argv.values['download-bytes'])).catch((err) => {
// eslint-disable-next-line no-console
console.error(err)
process.exit(1)
})

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import type { ComponentLogger, Libp2pEvents } from '@libp2p/interface';
import type { TypedEventTarget } from '@libp2p/interface/events';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { PeerStore } from '@libp2p/interface/peer-store';
import type { TransportManager } from '@libp2p/interface-internal/transport-manager';
import type { Multiaddr } from '@multiformats/multiaddr';
export interface AddressManagerInit {
/**
* Pass an function in this field to override the list of addresses
* that are announced to the network
*/
announceFilter?: AddressFilter;
/**
* list of multiaddrs string representation to listen
*/
listen?: string[];
/**
* list of multiaddrs string representation to announce
*/
announce?: string[];
/**
* list of multiaddrs string representation to never announce
*/
noAnnounce?: string[];
}
export interface DefaultAddressManagerComponents {
peerId: PeerId;
transportManager: TransportManager;
peerStore: PeerStore;
events: TypedEventTarget<Libp2pEvents>;
logger: ComponentLogger;
}
/**
* A function that takes a list of multiaddrs and returns a list
* to announce
*/
export interface AddressFilter {
(addrs: Multiaddr[]): Multiaddr[];
}
export declare class DefaultAddressManager {
private readonly log;
private readonly components;
private readonly listen;
private readonly announce;
private readonly observed;
private readonly announceFilter;
/**
* Responsible for managing the peer addresses.
* Peers can specify their listen and announce addresses.
* The listen addresses will be used by the libp2p transports to listen for new connections,
* while the announce addresses will be used for the peer addresses' to other peers in the network.
*/
constructor(components: DefaultAddressManagerComponents, init?: AddressManagerInit);
_updatePeerStoreAddresses(): void;
/**
* Get peer listen multiaddrs
*/
getListenAddrs(): Multiaddr[];
/**
* Get peer announcing multiaddrs
*/
getAnnounceAddrs(): Multiaddr[];
/**
* Get observed multiaddrs
*/
getObservedAddrs(): Multiaddr[];
/**
* Add peer observed addresses
*/
addObservedAddr(addr: Multiaddr): void;
confirmObservedAddr(addr: Multiaddr): void;
removeObservedAddr(addr: Multiaddr): void;
getAddresses(): Multiaddr[];
}
//# sourceMappingURL=index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function debounce(func: () => void, wait: number): () => void;
//# sourceMappingURL=utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07f755d

Please sign in to comment.