Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance TFramedTransport performance for nodejs #2483

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions lib/nodejs/lib/thrift/framed_transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,31 @@ function TFramedTransport(buffer, callback) {
TFramedTransport.prototype = new THeaderTransport();

TFramedTransport.receiver = function(callback, seqid) {
var residual = null;

var residual = [];
return function(data) {
Copy link
Member

@Jens-G Jens-G Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, still says "data".

return function(data) {

// Prepend any residual data from our previous read
if (residual) {
data = Buffer.concat([residual, data]);
residual = null;
// push received data to residual
for(var i = 0; i < data.length; ++i) {
residual.push(data[i])
}

// framed transport
while (data.length) {
if (data.length < 4) {
// Not enough bytes to continue, save and resume on next packet
residual = data;
while (residual.length > 0) {
if (residual.length < 4) {
// Not enough bytes to continue, save and resume on next packet
return;
}
var frameSize = binary.readI32(data, 0);
if (data.length < 4 + frameSize) {
// Not enough bytes to continue, save and resume on next packet
residual = data;
// get single package sieze
var frameSize = binary.readI32(Buffer.from(residual.slice(0, 4)), 0);
// Not enough bytes to continue, save and resume on next packet
if (residual.length < 4 + frameSize) {
return;
}

var frame = data.slice(4, 4 + frameSize);
residual = data.slice(4 + frameSize);

// splice first 4 bytes
residual.splice(0, 4)
// get package data
var frame = Buffer.from(residual.splice(0, frameSize));
callback(new TFramedTransport(frame), seqid);

data = residual;
residual = null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to "data"?

Copy link
Contributor Author

@wujjpp wujjpp Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined to residual, then if condition matched, splice(4) and splice(frameSize)

};
};
Expand Down