Skip to content

Commit 58d3789

Browse files
committed
[CONJS-132] Adding 'fast path' implementation: mysql packet usually never split header into multiple TCP packet
1 parent 1f2c257 commit 58d3789

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/io/compression-input-stream.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ class CompressionInputStream {
7070
do {
7171
if (this.remainingLen) {
7272
length = this.remainingLen;
73+
} else if (this.headerLen === 0 && chunkLen - pos >= 7) {
74+
this.header[0] = chunk[pos];
75+
this.header[1] = chunk[pos + 1];
76+
this.header[2] = chunk[pos + 2];
77+
this.header[3] = chunk[pos + 3];
78+
this.header[4] = chunk[pos + 4];
79+
this.header[5] = chunk[pos + 5];
80+
this.header[6] = chunk[pos + 6];
81+
this.headerLen = 7;
82+
pos += 7;
83+
this.compressPacketLen = this.header[0] + (this.header[1] << 8) + (this.header[2] << 16);
84+
this.packetLen = this.header[4] | (this.header[5] << 8) | (this.header[6] << 16);
85+
if (this.packetLen === 0) this.packetLen = this.compressPacketLen;
86+
length = this.compressPacketLen;
7387
} else {
7488
length = null;
7589
while (chunkLen - pos > 0) {

lib/io/packet-input-stream.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ class PacketInputStream {
128128
//read header
129129
if (this.remainingLen) {
130130
length = this.remainingLen;
131+
} else if (this.headerLen === 0 && chunkLen - pos >= 4) {
132+
this.header[0] = chunk[pos];
133+
this.header[1] = chunk[pos + 1];
134+
this.header[2] = chunk[pos + 2];
135+
this.header[3] = chunk[pos + 3];
136+
pos += 4;
137+
this.headerLen = 4;
138+
this.packetLen = this.header[0] + (this.header[1] << 8) + (this.header[2] << 16);
139+
length = this.packetLen;
131140
} else {
132141
length = null;
133142
while (chunkLen - pos > 0) {

test/conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let baseConfig = {
55
database: 'testn',
66
host: 'localhost',
77
connectTimeout: 1000,
8-
port: 3308
8+
port: 3306
99
};
1010

1111
if (process.env.TEST_HOST) baseConfig['host'] = process.env.TEST_HOST;

0 commit comments

Comments
 (0)