@libp2p/perf 2.0.1-05b52d69c → 2.0.1-6625a27fc

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 D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var k=(s,t)=>{for(var e in t)O(s,e,{get:t[e],enumerable:!0})},M=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of I(t))!v.call(s,n)&&n!==e&&O(s,n,{get:()=>t[n],enumerable:!(r=D(t,n))||r.enumerable});return s};var R=s=>M(O({},"__esModule",{value:!0}),s);var j={};k(j,{perf:()=>X});function x(){let s={};return s.promise=new Promise((t,e)=>{s.resolve=t,s.reject=e}),s}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 N=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function T(s={}){return z(e=>{let r=e.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},s)}function z(s,t){t=t??{};let e=t.onEnd,r=new b,n,l,u,a=x(),p=async()=>{try{return r.isEmpty()?u?{done:!0}:await new Promise((o,i)=>{l=S=>{l=null,r.push(S);try{o(s(r))}catch(w){i(w)}return n}}):s(r)}finally{r.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=x()})}},c=o=>l!=null?l(o):(r.push(o),n),y=o=>(r=new b,l!=null?l({error:o}):(r.push({error:o}),n)),m=o=>{if(u)return n;if(t?.objectMode!==!0&&o?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:o})},f=o=>u?n:(u=!0,o!=null?y(o):c({done:!0})),B=()=>(r=new b,f(),{done:!0}),h=o=>(f(o),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:p,return:B,throw:h,push:m,end:f,get readableLength(){return r.size},onEmpty:async o=>{let i=o?.signal;if(i?.throwIfAborted(),r.isEmpty())return;let S,w;i!=null&&(S=new Promise((K,A)=>{w=()=>{A(new N)},i.addEventListener("abort",w)}));try{await Promise.race([a.promise,S])}finally{w!=null&&i!=null&&i?.removeEventListener("abort",w)}}},e==null)return n;let d=n;return n={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(o){return d.throw(o),e!=null&&(e(o),e=void 0),{done:!0}},return(){return d.return(),e!=null&&(e(),e=void 0),{done:!0}},push:m,end(o){return d.end(o),e!=null&&(e(o),e=void 0),n},get readableLength(){return d.readableLength}},n}var _="/perf/1.0.0";var E=class{log;protocol;components;started;databuf;writeBlockSize;maxInboundStreams;maxOutboundStreams;runOnTransientConnection;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.databuf=new ArrayBuffer(this.writeBlockSize),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.runOnTransientConnection=e.runOnTransientConnection??!1}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,runOnTransientConnection:this.runOnTransientConnection}),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 r=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 l=new Uint8Array(this.databuf);await e.sink(async function*(){for(;n>0;){let u=r;u>n&&(u=n),n=n-u,yield l.subarray(0,u)}}())}catch(r){e.abort(r)}}async*measurePerformance(t,e,r,n={}){this.log("opening stream on protocol %s to %a",this.protocol,t);let l=new Uint8Array(this.databuf),u=this.writeBlockSize,a=Date.now(),p=await this.components.connectionManager.openConnection(t,{...n,force:n.reuseExistingConnection!==!0});yield{type:"connection",timeSeconds:(Date.now()-a)/1e3,uploadBytes:0,downloadBytes:0},a=Date.now();let c=await p.newStream(this.protocol,n),y=Date.now();yield{type:"stream",timeSeconds:(Date.now()-a)/1e3,uploadBytes:0,downloadBytes:0};let m=0;a=Date.now();let f=0;new DataView(this.databuf).setBigUint64(0,BigInt(r),!1),this.log("sending %i bytes to %p",e,p.remotePeer);try{let h=T({objectMode:!0});c.sink(async function*(){for(yield l.subarray(0,8),y=Date.now();e>0;){n.signal?.throwIfAborted();let i=u;i>e&&(i=e),e=e-i,yield l.subarray(0,i),Date.now()-a>1e3&&(h.push({type:"intermediary",timeSeconds:(Date.now()-a)/1e3,uploadBytes:m,downloadBytes:0}),a=Date.now(),m=0),m+=i,f+=i}h.end()}()).catch(i=>{h.end(i)}),yield*h;let d=0;a=Date.now();let o=0;for await(let i of c.source)n.signal?.throwIfAborted(),Date.now()-a>1e3&&(yield{type:"intermediary",timeSeconds:(Date.now()-a)/1e3,uploadBytes:0,downloadBytes:d},a=Date.now(),d=0),d+=i.byteLength,o+=i.byteLength;if(o!==r)throw new Error(`Expected to receive ${r} bytes, but received ${o}`);yield{type:"final",timeSeconds:(Date.now()-y)/1e3,uploadBytes:f,downloadBytes:o},this.log("performed %s to %p",this.protocol,p.remotePeer),await c.close()}catch(h){throw this.log("error sending %d/%d bytes to %p: %s",f,e,p.remotePeer,h),c.abort(h),h}}};function X(s={}){return t=>new E(t,s)}return R(j);})();
2
+ "use strict";var Libp2PPerf=(()=>{var O=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var M=(s,t)=>{for(var e in t)O(s,e,{get:t[e],enumerable:!0})},R=(s,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of I(t))!k.call(s,r)&&r!==e&&O(s,r,{get:()=>t[r],enumerable:!(o=v(t,r))||o.enumerable});return s};var z=s=>R(O({},"__esModule",{value:!0}),s);var j={};M(j,{perf:()=>X});function x(){let s={};return s.promise=new Promise((t,e)=>{s.resolve=t,s.reject=e}),s}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 N=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function B(s={}){return C(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}},s)}function C(s,t){t=t??{};let e=t.onEnd,o=new b,r,u,a,w=x(),p=async()=>{try{return o.isEmpty()?a?{done:!0}:await new Promise((n,i)=>{u=S=>{u=null,o.push(S);try{n(s(o))}catch(m){i(m)}return r}}):s(o)}finally{o.isEmpty()&&queueMicrotask(()=>{w.resolve(),w=x()})}},d=n=>u!=null?u(n):(o.push(n),r),y=n=>(o=new b,u!=null?u({error:n}):(o.push({error:n}),r)),l=n=>{if(a)return r;if(t?.objectMode!==!0&&n?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return d({done:!1,value:n})},f=n=>a?r:(a=!0,n!=null?y(n):d({done:!0})),T=()=>(o=new b,f(),{done:!0}),h=n=>(f(n),{done:!0});if(r={[Symbol.asyncIterator](){return this},next:p,return:T,throw:h,push:l,end:f,get readableLength(){return o.size},onEmpty:async n=>{let i=n?.signal;if(i?.throwIfAborted(),o.isEmpty())return;let S,m;i!=null&&(S=new Promise((K,A)=>{m=()=>{A(new N)},i.addEventListener("abort",m)}));try{await Promise.race([w.promise,S])}finally{m!=null&&i!=null&&i?.removeEventListener("abort",m)}}},e==null)return r;let c=r;return r={[Symbol.asyncIterator](){return this},next(){return c.next()},throw(n){return c.throw(n),e!=null&&(e(n),e=void 0),{done:!0}},return(){return c.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(n){return c.end(n),e!=null&&(e(n),e=void 0),r},get readableLength(){return c.readableLength},onEmpty:n=>c.onEmpty(n)},r}var _="/perf/1.0.0";var E=class{log;protocol;components;started;databuf;writeBlockSize;maxInboundStreams;maxOutboundStreams;runOnTransientConnection;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.databuf=new ArrayBuffer(this.writeBlockSize),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.runOnTransientConnection=e.runOnTransientConnection??!1}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,runOnTransientConnection:this.runOnTransientConnection}),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,r;for await(let a of e.source)r==null&&(r=Number(a.getBigUint64(0,!1)));if(r==null)throw new Error("bytesToSendBack was not set");let u=new Uint8Array(this.databuf,0,this.databuf.byteLength);await e.sink(async function*(){for(;r>0;){let a=o;a>r&&(a=r),r=r-a,yield u.subarray(0,a)}}())}catch(o){e.abort(o)}}async*measurePerformance(t,e,o,r={}){this.log("opening stream on protocol %s to %a",this.protocol,t);let u=new Uint8Array(this.databuf),a=this.writeBlockSize,w=Date.now(),p=await this.components.connectionManager.openConnection(t,{...r,force:r.reuseExistingConnection!==!0}),d=await p.newStream(this.protocol,r),y=0,l=Date.now(),f=0;new DataView(this.databuf).setBigUint64(0,BigInt(o),!1),this.log("sending %i bytes to %p",e,p.remotePeer);try{let h=B({objectMode:!0});d.sink(async function*(){for(yield u.subarray(0,8);e>0;){let i=a;i>e&&(i=e),yield u.subarray(0,i),e-=i,Date.now()-l>1e3&&(h.push({type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:y,downloadBytes:0}),l=Date.now(),y=0),y+=i,f+=i}h.end()}()).catch(i=>{h.end(i)}),yield*h;let c=0;l=Date.now();let n=0;for await(let i of d.source)Date.now()-l>1e3&&(yield{type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:0,downloadBytes:c},l=Date.now(),c=0),c+=i.byteLength,n+=i.byteLength;if(n!==o)throw new Error(`Expected to receive ${o} bytes, but received ${n}`);yield{type:"final",timeSeconds:(Date.now()-w)/1e3,uploadBytes:f,downloadBytes:n},this.log("performed %s to %p",this.protocol,p.remotePeer),await d.close()}catch(h){throw this.log("error sending %d/%d bytes to %p: %s",f,e,p.remotePeer,h),d.abort(h),h}}};function X(s={}){return t=>new E(t,s)}return z(j);})();
3
3
  return Libp2PPerf}));
@@ -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;AAE1G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,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;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAC3C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA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;IAC3C,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAS;gBAErC,UAAU,EAAE,cAAc,EAAE,IAAI,GAAE,QAAa;IAYtD,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAavB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAK5B,SAAS,IAAK,OAAO;IAIf,aAAa,CAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuCrD,kBAAkB,CAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,cAAc,CAAC,UAAU,CAAC;CA6K3I"}
@@ -55,7 +55,7 @@ export class Perf {
55
55
  if (bytesToSendBack == null) {
56
56
  throw new Error('bytesToSendBack was not set');
57
57
  }
58
- const uint8Buf = new Uint8Array(this.databuf);
58
+ const uint8Buf = new Uint8Array(this.databuf, 0, this.databuf.byteLength);
59
59
  await stream.sink(async function* () {
60
60
  while (bytesToSendBack > 0) {
61
61
  let toSend = writeBlockSize;
@@ -75,28 +75,14 @@ export class Perf {
75
75
  this.log('opening stream on protocol %s to %a', this.protocol, ma);
76
76
  const uint8Buf = new Uint8Array(this.databuf);
77
77
  const writeBlockSize = this.writeBlockSize;
78
- let lastReportedTime = Date.now();
78
+ const initialStartTime = Date.now();
79
79
  const connection = await this.components.connectionManager.openConnection(ma, {
80
80
  ...options,
81
81
  force: options.reuseExistingConnection !== true
82
82
  });
83
- yield {
84
- type: 'connection',
85
- timeSeconds: (Date.now() - lastReportedTime) / 1000,
86
- uploadBytes: 0,
87
- downloadBytes: 0
88
- };
89
- lastReportedTime = Date.now();
90
83
  const stream = await connection.newStream(this.protocol, options);
91
- let initialStartTime = Date.now();
92
- yield {
93
- type: 'stream',
94
- timeSeconds: (Date.now() - lastReportedTime) / 1000,
95
- uploadBytes: 0,
96
- downloadBytes: 0
97
- };
98
84
  let lastAmountOfBytesSent = 0;
99
- lastReportedTime = Date.now();
85
+ let lastReportedTime = Date.now();
100
86
  let totalBytesSent = 0;
101
87
  // tell the remote how many bytes we will send. Up cast to 64 bit number
102
88
  // as if we send as ui32 we limit total transfer size to 4GB
@@ -104,23 +90,20 @@ export class Perf {
104
90
  view.setBigUint64(0, BigInt(receiveBytes), false);
105
91
  this.log('sending %i bytes to %p', sendBytes, connection.remotePeer);
106
92
  try {
107
- const sendOutput = pushable({
93
+ const output = pushable({
108
94
  objectMode: true
109
95
  });
110
- void stream.sink(async function* () {
111
- // Send the number of bytes to receive
96
+ stream.sink(async function* () {
112
97
  yield uint8Buf.subarray(0, 8);
113
- initialStartTime = Date.now();
114
98
  while (sendBytes > 0) {
115
- options.signal?.throwIfAborted();
116
99
  let toSend = writeBlockSize;
117
100
  if (toSend > sendBytes) {
118
101
  toSend = sendBytes;
119
102
  }
120
- sendBytes = sendBytes - toSend;
121
103
  yield uint8Buf.subarray(0, toSend);
104
+ sendBytes -= toSend;
122
105
  if (Date.now() - lastReportedTime > 1000) {
123
- sendOutput.push({
106
+ output.push({
124
107
  type: 'intermediary',
125
108
  timeSeconds: (Date.now() - lastReportedTime) / 1000,
126
109
  uploadBytes: lastAmountOfBytesSent,
@@ -134,18 +117,78 @@ export class Perf {
134
117
  lastAmountOfBytesSent += toSend;
135
118
  totalBytesSent += toSend;
136
119
  }
137
- sendOutput.end();
120
+ output.end();
138
121
  }())
139
122
  .catch(err => {
140
- sendOutput.end(err);
123
+ output.end(err);
141
124
  });
142
- yield* sendOutput;
125
+ yield* output;
126
+ /*
127
+ const b = byteStream(stream)
128
+ await b.write(uint8Buf.subarray(0, 8), options)
129
+
130
+ while (sendBytes > 0) {
131
+ let toSend: number = writeBlockSize
132
+
133
+ if (toSend > sendBytes) {
134
+ toSend = sendBytes
135
+ }
136
+
137
+ const chunk = uint8Buf.subarray(0, toSend)
138
+
139
+ await b.write(chunk, options)
140
+
141
+ sendBytes -= toSend
142
+
143
+ if (Date.now() - lastReportedTime > 1000) {
144
+ yield {
145
+ type: 'intermediary',
146
+ timeSeconds: (Date.now() - lastReportedTime) / 1000,
147
+ uploadBytes: lastAmountOfBytesSent,
148
+ downloadBytes: 0
149
+ }
150
+
151
+ // record last reported time after `console.log` because it can
152
+ // affect benchmark timings
153
+ lastReportedTime = Date.now()
154
+ lastAmountOfBytesSent = 0
155
+ }
156
+
157
+ lastAmountOfBytesSent += toSend
158
+ totalBytesSent += toSend
159
+ }
160
+
161
+ // sent all the bytes, close the write end of the stream
162
+ await b.unwrap().closeWrite()
163
+
164
+ */
143
165
  // Read the received bytes
144
166
  let lastAmountOfBytesReceived = 0;
145
167
  lastReportedTime = Date.now();
146
168
  let totalBytesReceived = 0;
169
+ /*
170
+ while (totalBytesReceived < receiveBytes) {
171
+ const buf = await b.read(1024, options)
172
+
173
+ if (Date.now() - lastReportedTime > 1000) {
174
+ yield {
175
+ type: 'intermediary',
176
+ timeSeconds: (Date.now() - lastReportedTime) / 1000,
177
+ uploadBytes: 0,
178
+ downloadBytes: lastAmountOfBytesReceived
179
+ }
180
+
181
+ // record last reported time after `console.log` because it can
182
+ // affect benchmark timings
183
+ lastReportedTime = Date.now()
184
+ lastAmountOfBytesReceived = 0
185
+ }
186
+
187
+ lastAmountOfBytesReceived += buf.byteLength
188
+ totalBytesReceived += buf.byteLength
189
+ }
190
+ */
147
191
  for await (const buf of stream.source) {
148
- options.signal?.throwIfAborted();
149
192
  if (Date.now() - lastReportedTime > 1000) {
150
193
  yield {
151
194
  type: 'intermediary',
@@ -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,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAOxI,MAAM,OAAO,IAAI;IACE,GAAG,CAAQ;IACZ,QAAQ,CAAQ;I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BACxC,MAAM;wBACJ,IAAI,EAAE,cAAc;wBACpB,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC,GAAG,IAAI;wBACnD,WAAW,EAAE,CAAC;wBACd,aAAa,EAAE,yBAAyB;qBACzC,CAAA;oBAED,+DAA+D;oBAC/D,2BAA2B;oBAC3B,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;oBAC7B,yBAAyB,GAAG,CAAC,CAAA;iBAC9B;gBAED,yBAAyB,IAAI,GAAG,CAAC,UAAU,CAAA;gBAC3C,kBAAkB,IAAI,GAAG,CAAC,UAAU,CAAA;aACrC;YAED,IAAI,kBAAkB,KAAK,YAAY,EAAE;gBACvC,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,wBAAwB,kBAAkB,EAAE,CAAC,CAAA;aACjG;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;SACrB;QAAC,OAAO,GAAQ,EAAE;YACjB,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;SACV;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/perf",
3
- "version": "2.0.1-05b52d69c",
3
+ "version": "2.0.1-6625a27fc",
4
4
  "description": "Implementation of Perf Protocol",
5
5
  "author": "@maschad / @marcopolo",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -48,14 +48,14 @@
48
48
  "renderResults": "node dist/src/renderResults.js"
49
49
  },
50
50
  "dependencies": {
51
- "@libp2p/interface": "0.1.6-05b52d69c",
52
- "@libp2p/interface-internal": "0.1.9-05b52d69c",
51
+ "@libp2p/interface": "0.1.6-6625a27fc",
52
+ "@libp2p/interface-internal": "0.1.9-6625a27fc",
53
53
  "@multiformats/multiaddr": "^12.1.10",
54
- "it-pushable": "^3.2.1"
54
+ "it-pushable": "^3.2.3"
55
55
  },
56
56
  "devDependencies": {
57
- "@libp2p/logger": "3.1.0-05b52d69c",
58
- "@libp2p/interface-compliance-tests": "4.1.5-05b52d69c",
57
+ "@libp2p/interface-compliance-tests": "4.1.5-6625a27fc",
58
+ "@libp2p/logger": "3.1.0-6625a27fc",
59
59
  "aegir": "^41.0.2",
60
60
  "it-last": "^3.0.3",
61
61
  "it-pair": "^2.0.6",
@@ -64,6 +64,7 @@ export class Perf implements Startable, PerfInterface {
64
64
  // downcast 64 to 52 bits to avoid bigint arithmetic performance penalty
65
65
  bytesToSendBack = Number(buf.getBigUint64(0, false))
66
66
  }
67
+
67
68
  // Ingest all the bufs and wait for the read side to close
68
69
  }
69
70
 
@@ -71,7 +72,7 @@ export class Perf implements Startable, PerfInterface {
71
72
  throw new Error('bytesToSendBack was not set')
72
73
  }
73
74
 
74
- const uint8Buf = new Uint8Array(this.databuf)
75
+ const uint8Buf = new Uint8Array(this.databuf, 0, this.databuf.byteLength)
75
76
 
76
77
  await stream.sink(async function * () {
77
78
  while (bytesToSendBack > 0) {
@@ -95,34 +96,16 @@ export class Perf implements Startable, PerfInterface {
95
96
  const uint8Buf = new Uint8Array(this.databuf)
96
97
  const writeBlockSize = this.writeBlockSize
97
98
 
98
- let lastReportedTime = Date.now()
99
+ const initialStartTime = Date.now()
99
100
  const connection = await this.components.connectionManager.openConnection(ma, {
100
101
  ...options,
101
102
  force: options.reuseExistingConnection !== true
102
103
  })
103
104
 
104
- yield {
105
- type: 'connection',
106
- timeSeconds: (Date.now() - lastReportedTime) / 1000,
107
- uploadBytes: 0,
108
- downloadBytes: 0
109
- }
110
-
111
- lastReportedTime = Date.now()
112
-
113
105
  const stream = await connection.newStream(this.protocol, options)
114
106
 
115
- let initialStartTime = Date.now()
116
-
117
- yield {
118
- type: 'stream',
119
- timeSeconds: (Date.now() - lastReportedTime) / 1000,
120
- uploadBytes: 0,
121
- downloadBytes: 0
122
- }
123
-
124
107
  let lastAmountOfBytesSent = 0
125
- lastReportedTime = Date.now()
108
+ let lastReportedTime = Date.now()
126
109
  let totalBytesSent = 0
127
110
 
128
111
  // tell the remote how many bytes we will send. Up cast to 64 bit number
@@ -133,28 +116,26 @@ export class Perf implements Startable, PerfInterface {
133
116
  this.log('sending %i bytes to %p', sendBytes, connection.remotePeer)
134
117
 
135
118
  try {
136
- const sendOutput = pushable<PerfOutput>({
119
+ const output = pushable<PerfOutput>({
137
120
  objectMode: true
138
121
  })
139
122
 
140
- void stream.sink(async function * () {
141
- // Send the number of bytes to receive
123
+ stream.sink(async function * () {
142
124
  yield uint8Buf.subarray(0, 8)
143
125
 
144
- initialStartTime = Date.now()
145
-
146
126
  while (sendBytes > 0) {
147
- options.signal?.throwIfAborted()
148
-
149
127
  let toSend: number = writeBlockSize
128
+
150
129
  if (toSend > sendBytes) {
151
130
  toSend = sendBytes
152
131
  }
153
- sendBytes = sendBytes - toSend
132
+
154
133
  yield uint8Buf.subarray(0, toSend)
155
134
 
135
+ sendBytes -= toSend
136
+
156
137
  if (Date.now() - lastReportedTime > 1000) {
157
- sendOutput.push({
138
+ output.push({
158
139
  type: 'intermediary',
159
140
  timeSeconds: (Date.now() - lastReportedTime) / 1000,
160
141
  uploadBytes: lastAmountOfBytesSent,
@@ -171,22 +152,80 @@ export class Perf implements Startable, PerfInterface {
171
152
  totalBytesSent += toSend
172
153
  }
173
154
 
174
- sendOutput.end()
155
+ output.end()
175
156
  }())
176
157
  .catch(err => {
177
- sendOutput.end(err)
158
+ output.end(err)
178
159
  })
179
160
 
180
- yield * sendOutput
161
+ yield * output
162
+
163
+ /*
164
+ const b = byteStream(stream)
165
+ await b.write(uint8Buf.subarray(0, 8), options)
166
+
167
+ while (sendBytes > 0) {
168
+ let toSend: number = writeBlockSize
169
+
170
+ if (toSend > sendBytes) {
171
+ toSend = sendBytes
172
+ }
173
+
174
+ const chunk = uint8Buf.subarray(0, toSend)
175
+
176
+ await b.write(chunk, options)
177
+
178
+ sendBytes -= toSend
179
+
180
+ if (Date.now() - lastReportedTime > 1000) {
181
+ yield {
182
+ type: 'intermediary',
183
+ timeSeconds: (Date.now() - lastReportedTime) / 1000,
184
+ uploadBytes: lastAmountOfBytesSent,
185
+ downloadBytes: 0
186
+ }
181
187
 
188
+ // record last reported time after `console.log` because it can
189
+ // affect benchmark timings
190
+ lastReportedTime = Date.now()
191
+ lastAmountOfBytesSent = 0
192
+ }
193
+
194
+ lastAmountOfBytesSent += toSend
195
+ totalBytesSent += toSend
196
+ }
197
+
198
+ // sent all the bytes, close the write end of the stream
199
+ await b.unwrap().closeWrite()
200
+
201
+ */
182
202
  // Read the received bytes
183
203
  let lastAmountOfBytesReceived = 0
184
204
  lastReportedTime = Date.now()
185
205
  let totalBytesReceived = 0
206
+ /*
207
+ while (totalBytesReceived < receiveBytes) {
208
+ const buf = await b.read(1024, options)
186
209
 
187
- for await (const buf of stream.source) {
188
- options.signal?.throwIfAborted()
210
+ if (Date.now() - lastReportedTime > 1000) {
211
+ yield {
212
+ type: 'intermediary',
213
+ timeSeconds: (Date.now() - lastReportedTime) / 1000,
214
+ uploadBytes: 0,
215
+ downloadBytes: lastAmountOfBytesReceived
216
+ }
189
217
 
218
+ // record last reported time after `console.log` because it can
219
+ // affect benchmark timings
220
+ lastReportedTime = Date.now()
221
+ lastAmountOfBytesReceived = 0
222
+ }
223
+
224
+ lastAmountOfBytesReceived += buf.byteLength
225
+ totalBytesReceived += buf.byteLength
226
+ }
227
+ */
228
+ for await (const buf of stream.source) {
190
229
  if (Date.now() - lastReportedTime > 1000) {
191
230
  yield {
192
231
  type: 'intermediary',