@libp2p/perf 4.0.25-a4f0db1e9 → 4.0.26-5b084e968
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPerf = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PPerf=(()=>{var O=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(i,t)=>{for(var e in t)O(i,e,{get:t[e],enumerable:!0})},k=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!M.call(i,n)&&n!==e&&O(i,n,{get:()=>t[n],enumerable:!(o=I(t,n))||o.enumerable});return i};var A=i=>k(O({},"__esModule",{value:!0}),i);var j={};v(j,{perf:()=>X});function S(){let i={};return i.promise=new Promise((t,e)=>{i.resolve=t,i.reject=e}),i}var g=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},b=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new g(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new g(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var B=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function N(i={}){return z(e=>{let o=e.shift();if(o==null)return{done:!0};if(o.error!=null)throw o.error;return{done:o.done===!0,value:o.value}},i)}function z(i,t){t=t??{};let e=t.onEnd,o=new b,n,
|
2
|
+
"use strict";var Libp2PPerf=(()=>{var O=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(i,t)=>{for(var e in t)O(i,e,{get:t[e],enumerable:!0})},k=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!M.call(i,n)&&n!==e&&O(i,n,{get:()=>t[n],enumerable:!(o=I(t,n))||o.enumerable});return i};var A=i=>k(O({},"__esModule",{value:!0}),i);var j={};v(j,{perf:()=>X});function S(){let i={};return i.promise=new Promise((t,e)=>{i.resolve=t,i.reject=e}),i}var g=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},b=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new g(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new g(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var B=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function N(i={}){return z(e=>{let o=e.shift();if(o==null)return{done:!0};if(o.error!=null)throw o.error;return{done:o.done===!0,value:o.value}},i)}function z(i,t){t=t??{};let e=t.onEnd,o=new b,n,c,u,y=S(),l=async()=>{try{return o.isEmpty()?u?{done:!0}:await new Promise((r,h)=>{c=w=>{c=null,o.push(w);try{r(i(o))}catch(s){h(s)}return n}}):i(o)}finally{o.isEmpty()&&queueMicrotask(()=>{y.resolve(),y=S()})}},d=r=>c!=null?c(r):(o.push(r),n),p=r=>(o=new b,c!=null?c({error:r}):(o.push({error:r}),n)),m=r=>{if(u)return n;if(t?.objectMode!==!0&&r?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return d({done:!1,value:r})},f=r=>u?n:(u=!0,r!=null?p(r):d({done:!0})),E=()=>(o=new b,f(),{done:!0}),D=r=>(f(r),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:l,return:E,throw:D,push:m,end:f,get readableLength(){return o.size},onEmpty:async r=>{let h=r?.signal;if(h?.throwIfAborted(),o.isEmpty())return;let w,s;h!=null&&(w=new Promise((K,L)=>{s=()=>{L(new B)},h.addEventListener("abort",s)}));try{await Promise.race([y.promise,w])}finally{s!=null&&h!=null&&h?.removeEventListener("abort",s)}}},e==null)return n;let a=n;return n={[Symbol.asyncIterator](){return this},next(){return a.next()},throw(r){return a.throw(r),e!=null&&(e(r),e=void 0),{done:!0}},return(){return a.return(),e!=null&&(e(),e=void 0),{done:!0}},push:m,end(r){return a.end(r),e!=null&&(e(r),e=void 0),n},get readableLength(){return a.readableLength},onEmpty:r=>a.onEmpty(r)},n}var _="/perf/1.0.0";var x=class{log;protocol;components;started;buf;writeBlockSize;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;constructor(t,e={}){this.components=t,this.log=t.logger.forComponent("libp2p:perf"),this.started=!1,this.protocol=e.protocolName??_,this.writeBlockSize=e.writeBlockSize??65536,this.buf=new ArrayBuffer(this.writeBlockSize),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.runOnLimitedConnection=e.runOnLimitedConnection??!1}[Symbol.toStringTag]="@libp2p/perf";async start(){await this.components.registrar.handle(this.protocol,t=>{this.handleMessage(t).catch(e=>{this.log.error("error handling perf protocol message",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async handleMessage(t){let{stream:e}=t;try{let o=this.writeBlockSize,n;for await(let u of e.source)n==null&&(n=Number(u.getBigUint64(0,!1)));if(n==null)throw new Error("bytesToSendBack was not set");let c=new Uint8Array(this.buf,0,this.buf.byteLength);await e.sink(async function*(){for(;n>0;){let u=o;u>n&&(u=n),n=n-u,yield c.subarray(0,u)}}())}catch(o){e.abort(o)}}async*measurePerformance(t,e,o,n={}){this.log("opening stream on protocol %s to %a",this.protocol,t);let c=new Uint8Array(this.buf),u=this.writeBlockSize,y=Date.now(),l=Date.now(),d=await this.components.connectionManager.openConnection(t,{...n,force:n.reuseExistingConnection!==!0});this.log("opened connection after %d ms",Date.now()-l),l=Date.now();let p=await d.newStream(this.protocol,n);this.log("opened stream after %d ms",Date.now()-l),l=Date.now();let m=0,f=0,E=Date.now();new DataView(this.buf).setBigUint64(0,BigInt(o),!1),this.log("sending %i bytes to %p",e,d.remotePeer);try{let a=N({objectMode:!0});p.sink(async function*(){for(yield c.subarray(0,8);e>0;){let s=u;s>e&&(s=e),yield c.subarray(0,s),e-=s,Date.now()-l>1e3&&(a.push({type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:m,downloadBytes:0}),l=Date.now(),m=0),m+=s,f+=s}a.end()}()).catch(s=>{a.end(s)}),yield*a,this.log("upload complete after %d ms",Date.now()-E);let r=0;l=Date.now();let h=0,w=Date.now();for await(let s of p.source)Date.now()-l>1e3&&(yield{type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:0,downloadBytes:r},l=Date.now(),r=0),r+=s.byteLength,h+=s.byteLength;if(this.log("download complete after %d ms",Date.now()-w),h!==o)throw new Error(`Expected to receive ${o} bytes, but received ${h}`);yield{type:"final",timeSeconds:(Date.now()-y)/1e3,uploadBytes:f,downloadBytes:h},this.log("performed %s to %p",this.protocol,d.remotePeer),await p.close()}catch(a){throw this.log("error sending %d/%d bytes to %p: %s",f,e,d.remotePeer,a),p.abort(a),a}}};function X(i={}){return t=>new x(t,i)}return A(j);})();
|
3
3
|
return Libp2PPerf}));
|
@@ -6,7 +6,7 @@ export declare class Perf implements Startable, PerfInterface {
|
|
6
6
|
readonly protocol: string;
|
7
7
|
private readonly components;
|
8
8
|
private started;
|
9
|
-
private readonly
|
9
|
+
private readonly buf;
|
10
10
|
private readonly writeBlockSize;
|
11
11
|
private readonly maxInboundStreams;
|
12
12
|
private readonly maxOutboundStreams;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"perf-service.d.ts","sourceRoot":"","sources":["../../src/perf-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1G,OAAO,KAAK,EAAU,SAAS,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,qBAAa,IAAK,YAAW,SAAS,EAAE,aAAa;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,SAAgB,QAAQ,EAAE,MAAM,CAAA;IA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,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,cAAc,CAAC,UAAU,CAAC;CA6H3I"}
|
package/dist/src/perf-service.js
CHANGED
@@ -5,7 +5,7 @@ export class Perf {
|
|
5
5
|
protocol;
|
6
6
|
components;
|
7
7
|
started;
|
8
|
-
|
8
|
+
buf;
|
9
9
|
writeBlockSize;
|
10
10
|
maxInboundStreams;
|
11
11
|
maxOutboundStreams;
|
@@ -16,7 +16,7 @@ export class Perf {
|
|
16
16
|
this.started = false;
|
17
17
|
this.protocol = init.protocolName ?? PROTOCOL_NAME;
|
18
18
|
this.writeBlockSize = init.writeBlockSize ?? WRITE_BLOCK_SIZE;
|
19
|
-
this.
|
19
|
+
this.buf = new ArrayBuffer(this.writeBlockSize);
|
20
20
|
this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS;
|
21
21
|
this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS;
|
22
22
|
this.runOnLimitedConnection = init.runOnLimitedConnection ?? RUN_ON_LIMITED_CONNECTION;
|
@@ -51,12 +51,12 @@ export class Perf {
|
|
51
51
|
// downcast 64 to 52 bits to avoid bigint arithmetic performance penalty
|
52
52
|
bytesToSendBack = Number(buf.getBigUint64(0, false));
|
53
53
|
}
|
54
|
-
// Ingest all the
|
54
|
+
// Ingest all the data and wait for the read side to close
|
55
55
|
}
|
56
56
|
if (bytesToSendBack == null) {
|
57
57
|
throw new Error('bytesToSendBack was not set');
|
58
58
|
}
|
59
|
-
const uint8Buf = new Uint8Array(this.
|
59
|
+
const uint8Buf = new Uint8Array(this.buf, 0, this.buf.byteLength);
|
60
60
|
await stream.sink(async function* () {
|
61
61
|
while (bytesToSendBack > 0) {
|
62
62
|
let toSend = writeBlockSize;
|
@@ -74,7 +74,7 @@ export class Perf {
|
|
74
74
|
}
|
75
75
|
async *measurePerformance(ma, sendBytes, receiveBytes, options = {}) {
|
76
76
|
this.log('opening stream on protocol %s to %a', this.protocol, ma);
|
77
|
-
const uint8Buf = new Uint8Array(this.
|
77
|
+
const uint8Buf = new Uint8Array(this.buf);
|
78
78
|
const writeBlockSize = this.writeBlockSize;
|
79
79
|
const initialStartTime = Date.now();
|
80
80
|
let lastReportedTime = Date.now();
|
@@ -92,7 +92,7 @@ export class Perf {
|
|
92
92
|
const uploadStart = Date.now();
|
93
93
|
// tell the remote how many bytes we will send. Up cast to 64 bit number
|
94
94
|
// as if we send as ui32 we limit total transfer size to 4GB
|
95
|
-
const view = new DataView(this.
|
95
|
+
const view = new DataView(this.buf);
|
96
96
|
view.setBigUint64(0, BigInt(receiveBytes), false);
|
97
97
|
this.log('sending %i bytes to %p', sendBytes, connection.remotePeer);
|
98
98
|
try {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"perf-service.js","sourceRoot":"","sources":["../../src/perf-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAKtI,MAAM,OAAO,IAAI;IACE,GAAG,CAAQ;IACZ,QAAQ,CAAQ;IACf,UAAU,CAAgB;IACnC,OAAO,CAAS;IACP,
|
1
|
+
{"version":3,"file":"perf-service.js","sourceRoot":"","sources":["../../src/perf-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAKtI,MAAM,OAAO,IAAI;IACE,GAAG,CAAQ;IACZ,QAAQ,CAAQ;IACf,UAAU,CAAgB;IACnC,OAAO,CAAS;IACP,GAAG,CAAa;IAChB,cAAc,CAAQ;IACtB,iBAAiB,CAAQ;IACzB,kBAAkB,CAAQ;IAC1B,sBAAsB,CAAS;IA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,EAAE,GAAG,aAAa,CAAC,CAAA;YAErE,IAAI,kBAAkB,KAAK,YAAY,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,wBAAwB,kBAAkB,EAAE,CAAC,CAAA;YAClG,CAAC;YAED,MAAM;gBACJ,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC,GAAG,IAAI;gBACnD,WAAW,EAAE,cAAc;gBAC3B,aAAa,EAAE,kBAAkB;aAClC,CAAA;YAED,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,CAAA;YACpE,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QACtB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,qCAAqC,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;YACtG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACjB,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/perf",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.26-5b084e968",
|
4
4
|
"description": "Implementation of Perf Protocol",
|
5
5
|
"author": "@maschad / @marcopolo",
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
@@ -52,14 +52,14 @@
|
|
52
52
|
"doc-check": "aegir doc-check"
|
53
53
|
},
|
54
54
|
"dependencies": {
|
55
|
-
"@libp2p/interface": "2.6.0-
|
56
|
-
"@libp2p/interface-internal": "2.3.
|
55
|
+
"@libp2p/interface": "2.6.0-5b084e968",
|
56
|
+
"@libp2p/interface-internal": "2.3.4-5b084e968",
|
57
57
|
"@multiformats/multiaddr": "^12.3.3",
|
58
58
|
"it-pushable": "^3.2.3"
|
59
59
|
},
|
60
60
|
"devDependencies": {
|
61
|
-
"@libp2p/interface-compliance-tests": "6.3.
|
62
|
-
"@libp2p/logger": "5.1.9-
|
61
|
+
"@libp2p/interface-compliance-tests": "6.3.4-5b084e968",
|
62
|
+
"@libp2p/logger": "5.1.9-5b084e968",
|
63
63
|
"aegir": "^45.0.5",
|
64
64
|
"it-last": "^3.0.6",
|
65
65
|
"it-pair": "^2.0.6",
|
package/src/perf-service.ts
CHANGED
@@ -9,7 +9,7 @@ export class Perf implements Startable, PerfInterface {
|
|
9
9
|
public readonly protocol: string
|
10
10
|
private readonly components: PerfComponents
|
11
11
|
private started: boolean
|
12
|
-
private readonly
|
12
|
+
private readonly buf: ArrayBuffer
|
13
13
|
private readonly writeBlockSize: number
|
14
14
|
private readonly maxInboundStreams: number
|
15
15
|
private readonly maxOutboundStreams: number
|
@@ -21,7 +21,7 @@ export class Perf implements Startable, PerfInterface {
|
|
21
21
|
this.started = false
|
22
22
|
this.protocol = init.protocolName ?? PROTOCOL_NAME
|
23
23
|
this.writeBlockSize = init.writeBlockSize ?? WRITE_BLOCK_SIZE
|
24
|
-
this.
|
24
|
+
this.buf = new ArrayBuffer(this.writeBlockSize)
|
25
25
|
this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS
|
26
26
|
this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS
|
27
27
|
this.runOnLimitedConnection = init.runOnLimitedConnection ?? RUN_ON_LIMITED_CONNECTION
|
@@ -65,14 +65,14 @@ export class Perf implements Startable, PerfInterface {
|
|
65
65
|
bytesToSendBack = Number(buf.getBigUint64(0, false))
|
66
66
|
}
|
67
67
|
|
68
|
-
// Ingest all the
|
68
|
+
// Ingest all the data and wait for the read side to close
|
69
69
|
}
|
70
70
|
|
71
71
|
if (bytesToSendBack == null) {
|
72
72
|
throw new Error('bytesToSendBack was not set')
|
73
73
|
}
|
74
74
|
|
75
|
-
const uint8Buf = new Uint8Array(this.
|
75
|
+
const uint8Buf = new Uint8Array(this.buf, 0, this.buf.byteLength)
|
76
76
|
|
77
77
|
await stream.sink(async function * () {
|
78
78
|
while (bytesToSendBack > 0) {
|
@@ -93,7 +93,7 @@ export class Perf implements Startable, PerfInterface {
|
|
93
93
|
async * measurePerformance (ma: Multiaddr, sendBytes: number, receiveBytes: number, options: PerfOptions = {}): AsyncGenerator<PerfOutput> {
|
94
94
|
this.log('opening stream on protocol %s to %a', this.protocol, ma)
|
95
95
|
|
96
|
-
const uint8Buf = new Uint8Array(this.
|
96
|
+
const uint8Buf = new Uint8Array(this.buf)
|
97
97
|
const writeBlockSize = this.writeBlockSize
|
98
98
|
|
99
99
|
const initialStartTime = Date.now()
|
@@ -117,7 +117,7 @@ export class Perf implements Startable, PerfInterface {
|
|
117
117
|
|
118
118
|
// tell the remote how many bytes we will send. Up cast to 64 bit number
|
119
119
|
// as if we send as ui32 we limit total transfer size to 4GB
|
120
|
-
const view = new DataView(this.
|
120
|
+
const view = new DataView(this.buf)
|
121
121
|
view.setBigUint64(0, BigInt(receiveBytes), false)
|
122
122
|
|
123
123
|
this.log('sending %i bytes to %p', sendBytes, connection.remotePeer)
|