Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge 3954f1e into d22dff7
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-palmer committed May 16, 2019
2 parents d22dff7 + 3954f1e commit 8c27b28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/server/command_processor.js
Expand Up @@ -59,8 +59,9 @@ class CommandProcessor extends Duplex {
this._sendFileQueueChunkReads = 0;
this._sendFileQueueReadDuration = 0;
this._sendFileQueueReadBytes = 0;
this._sendFileQueueCount = 0;
this._sendFileQueueSize = 0;
this._sendFileQueueIndex = 0;
this._sentFileCount = 0;
this._isReading = false;
this._testReadStreamDestroy = false;
this._clientAddress = "(unknown)";
Expand All @@ -83,6 +84,22 @@ class CommandProcessor extends Duplex {
return this._clientAddress;
}

/**
*
* @returns {number}
*/
get sentFileCount() {
return this._sentFileCount;
}

/**
*
* @returns {number}
*/
get sendFileQueueSize() {
return this._sendFileQueueSize;
}

get _sendFileQueueLength() {
const q = this[kSendFileQueue];
return q ? q.length - this._sendFileQueueIndex : 0;
Expand Down Expand Up @@ -192,6 +209,7 @@ class CommandProcessor extends Duplex {

this[kCache].getFileStream(file.type, file.guid, file.hash)
.then(stream => {
this._sentFileCount++;
this[kReadStream] = stream;
this._readStartTime = Date.now();
this.push(this._responseHeader(file), 'ascii');
Expand Down Expand Up @@ -222,7 +240,7 @@ class CommandProcessor extends Duplex {
if(this._sendFileQueueReadDuration > 0) {
const totalTime = this._sendFileQueueReadDuration / 1000;
const throughput = (this._sendFileQueueReadBytes / totalTime).toFixed(2);
helpers.log(consts.LOG_INFO, `Sent ${this._sendFileQueueIndex} of ${this._sendFileQueueCount} requested files (${this._sendFileQueueChunkReads} chunks) totaling ${filesize(this._sendFileQueueReadBytes)} in ${totalTime} seconds (${filesize(throughput)}/sec) to ${this.clientAddress}`);
helpers.log(consts.LOG_INFO, `Sent ${this.sentFileCount} of ${this.sendFileQueueSize} requested files (${this._sendFileQueueChunkReads} chunks) totaling ${filesize(this._sendFileQueueReadBytes)} in ${totalTime} seconds (${filesize(throughput)}/sec) to ${this.clientAddress}`);
}
}

Expand Down Expand Up @@ -342,7 +360,7 @@ class CommandProcessor extends Duplex {
const info = await this[kCache].getFileInfo(type, guid, hash);
item.exists = true;
item.size = info.size;
this._sendFileQueueCount++;
this._sendFileQueueSize++;
helpers.log(consts.LOG_DBG, `Adding file to send queue, size ${info.size}`);
}
catch(err) {
Expand Down
2 changes: 2 additions & 0 deletions test/protocol.js
Expand Up @@ -287,6 +287,7 @@ describe("Protocol", () => {
resp.on('data', () => {});
resp.on('dataEnd', () => {
if(cmds.length === 0) {
assert.strictEqual(cmdProc.sentFileCount, 4);
done();
}
});
Expand Down Expand Up @@ -317,6 +318,7 @@ describe("Protocol", () => {
resp.on('data', () => {});
resp.on('dataEnd', () => {
if(cmds.length === 0) {
assert.strictEqual(cmdProc.sentFileCount, 4);
done();
}
});
Expand Down

0 comments on commit 8c27b28

Please sign in to comment.