Skip to content

child_process: introduce binary protocol to optimizing performance#393

Merged
yorkie merged 16 commits intomasterfrom
optimize/child_process-ipc
Oct 25, 2018
Merged

child_process: introduce binary protocol to optimizing performance#393
yorkie merged 16 commits intomasterfrom
optimize/child_process-ipc

Conversation

@qile222
Copy link
Copy Markdown
Contributor

@qile222 qile222 commented Oct 25, 2018

No description provided.

chenximin added 10 commits October 24, 2018 03:10
@qile222 qile222 requested review from legendecas and yorkie October 25, 2018 18:32
Copy link
Copy Markdown
Member

@yorkie yorkie left a comment

Choose a reason for hiding this comment

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

Nice works, there are some suggestions to leave, please fix those @lolBig.

return offset + 4;
};

Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should add some comments like:

// buff.readUInt8(offset[,noAssert])
// [1] buff.readUInt8(offset)
 // [2] buff.readUInt8(offset, noAssert)

(this._builtin.readUInt8(offset + 3) << 24);
};

Buffer.prototype.readInt32BE = function(offset, noAssert) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, BTW you need to update our Buffer docs, too.

var SIGNAL_NO = constants.os.signals;
var INTERNAL_IPC_HEADER_LENGTH_SIZE = constants.INTERNAL_IPC_HEADER_LENGTH_SIZE;
var INTERNAL_IPC_HEADER_SIZE = constants.INTERNAL_IPC_HEADER_SIZE;
var INTERNAL_IPC_PAYLOAD_MAX_SIZE = constants.INTERNAL_IPC_PAYLOAD_MAX_SIZE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Define all above constants only in child_process.js if those won't be used by others?

var dataSize = channel.pendingBuffer.readInt32BE(headerOffset);
var typeOffset = headerOffset + INTERNAL_IPC_HEADER_LENGTH_SIZE;
var dataType = channel.pendingBuffer.readInt32BE(typeOffset);
var dataBegin = headerOffset + INTERNAL_IPC_HEADER_SIZE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we have an abstracted IpcMessage class like the following:

while (bufLength - headerOffset >= INTERNAL_IPC_HEADER_SIZE) {
  var message = new IpcMessage(channel);
  // ...
  if (message.isObject()) { }
}

message = message.toString();
} else {
throw new Error('ERR_IPC_MESSAGE_TYPE_INVALID');
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, we could add a method serialize() on IpcMessage to make it read easier :)

write_data->data = malloc(sizeof(char) * size);
memcpy(write_data->data, data, size);
write_data->callback = callback;
uv_write_t* write_req = IOTJS_ALLOC(uv_write_t);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about make iotjs_write_data to be iotjs_write_wrap like the following:

typedef struct iotjs_pipe_write_data {
  char* data;
  uv_write_t req;
  jerry_value_t callback;
} iotjs_pipe_write_data;

So we could only need to malloc once :)

iotjs_jval_set_method(proto, "listen", PipeListen);
// iotjs_jval_set_method(proto, "connect", PipeConnect);
iotjs_jval_set_method(proto, "readStart", PipeReadStart);
iotjs_jval_set_method(proto, "write", Write);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's better to use MAGIC_STRING :)

var assert = require('assert');
// json length is close to 19KB
var data = require('./test_process_send.json');
var dataStr = JSON.stringify(data)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The semi-colon :(

// json length is close to 19KB
var data = require('./test_process_send.json');
var dataStr = JSON.stringify(data)
var name = process.send ? 'child' : 'parent'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto.

if (times <= 0) {
clearInterval(timer);
}
}, 500) No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test is more like as a benchmark script, we actually need the unit tests, could you please add an case that just acquire the API works and move this to benchmark?

@yorkie
Copy link
Copy Markdown
Member

yorkie commented Oct 25, 2018

By the way, @lolBig you forget to add your test into "testsets.json" :)

chenximin added 2 commits October 26, 2018 03:28
#define IOTJS_MAGIC_STRING_WRITESYNC "writeSync"
#define IOTJS_MAGIC_STRING_WRITEUINT8 "writeUInt8"
#define IOTJS_MAGIC_STRING_WRITE "write"
#define IOTJS_MAGIC_STRING_WRITE_UTF8_STRING "writeUtf8String"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IOTJS_MAGIC_STRING_WRITEUTF8STRING


static void iotjs_pipe_after_write(uv_write_t* req, int status) {
jerry_value_t callback = (jerry_value_t)(uintptr_t)req->data;
iotjs_write_wrap* write_data = (iotjs_write_wrap*)req->data;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use the writer_wrap instead of write_data

Copy link
Copy Markdown
Member

@yorkie yorkie left a comment

Choose a reason for hiding this comment

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

LGTM if CI is green.

@yorkie yorkie changed the title child_process: optimize ipc child_process: introduce binary protocol to optimizing performance Oct 25, 2018
chenximin added 2 commits October 26, 2018 04:24
@yorkie yorkie merged commit 60ea12e into master Oct 25, 2018
@yorkie yorkie deleted the optimize/child_process-ipc branch October 25, 2018 21:49
qile222 pushed a commit that referenced this pull request Oct 27, 2018
* master:
  build: use CMAKE_INSTALL_PREFIX instead of custom install command (#391)
  child_process: introduce binary protocol to optimizing performance (#393)
  iotjs: cache parsed dump table for error.stack at runtime (#392)
  jerry: merge a59cf4f from upstream to optimize the function call (#381)
  promise: optimize the performance on .then and static resolve (#385)
  jerry: set prototype/constructor for external functions (#386)
  process: add shebang parser supports (#379)
  napi: fix complete callback segv/ticks on async-work (#380)
  jerry: pass regression-test-issue-2105 for heapdump (#382)
  tls, mqtts: fix connection not be actively disconnected (#375)
  websocket: fix the crash due to http exception (#376)
  process: add signal events support (#372)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants