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

lib: optimize connection events #222

Closed
wants to merge 3 commits into from
Closed

Conversation

lundibundi
Copy link
Member

@lundibundi lundibundi commented Jun 16, 2017

  • remove unnecessary events like 'handshake', 'call', 'handshakeRequest'
  • replace 'callbackForUnknownPacket' with rejectPacket
  • change signature of connection 'event' (remote event), now it contains
    interfaceName, eventName, eventArgs

Also event though state packet event is now removed it has to be put back with proper data inside the event, because _emitPacketEvent it used adds a lot of redundant data. Can you please comment on which data should be included in state event?
UPD: as discused state packets are removed for now.

Fixes: #49

@belochub
Copy link
Member

I think that it is better to add logger functionality in a different PR or at least in a different commit in this PR because it isn't really connected to connection events optimization.

@belochub
Copy link
Member

Also, it would be great to have an ability to add multiple loggers instead of setting just one.

@lundibundi
Copy link
Member Author

lundibundi commented Jun 16, 2017

@belochub yeah, different commit I guess even though the change is good enough to be in a different PR I think there is no need in that because that PR will not have any actual usages of logger, so even if you set the logger it will do nothing, but having a different PR is fine with me too.

Could you elaborate on the latter comment, what multiple loggers can you have?

@belochub
Copy link
Member

I meant that you can create a new PR based on this PR with logger functionality.

About multiple loggers, there is a lot of possible variants, for example, one logger for console output, another for file logging and the third for logging over the network. Of course, it can be implemented even with the current changes, but it will be much easier if you add a possibility to add multiple loggers.

@lundibundi
Copy link
Member Author

@belochub I do not see any reason to implement it here, I think that's the job of a logging framework user decides to use with our project, the logger I add here is just an api (at least winston and bunyan can do that pretty good).

@belochub
Copy link
Member

Yeah, but it will do no harm if you add the possibility to have multiple loggers. It will make it possible to use small and simple self-written loggers instead of bigger frameworks, and you can still use the frameworks by adding just one logger instance.

@lundibundi
Copy link
Member Author

As discussed, waiting for #224.

* remove unnecessary events like 'handshake', 'call', 'handshakeRequest'
* replace 'callbackForUnknownPacket' with rejectPacket
* change signature of connection 'event' (remote event), now it contains
  interfaceName, eventName, eventArgs

Fixes: #49
@lundibundi
Copy link
Member Author

Properly split changes, removing blocked.

Copy link
Member

@aqrln aqrln left a comment

Choose a reason for hiding this comment

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

LGTM with nits.

@@ -58,6 +58,10 @@ function Connection(transport, server, client) {

this._heartbeatCallbackInstance = null;

this._emitError = (error) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment explaining the reason of this being created in the constructor instead of on the prototype? It is not immediately obvious until one reads the callMethod() code.

test.strictEqual(event.interfaceName, iface,
server.getClients()[0].on('event',
(interfaceName, remoteName, remoteArgs) => {
test.strictEqual(interfaceName, iface,
'event interface must match');
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can you please indent this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. We should find a way to track it automatically =).

Copy link
Member

Choose a reason for hiding this comment

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

It will be tracked automatically as soon as we update ESLint to 4.0. The only reason I haven't done it yet is that we use the eslint-plugin-import plugin which still has eslint@3.x as its peerDependency (though it seems to work with the latest eslint nevertheless).

'event interface must match');
test.strictEqual(event.remoteEventName, eventName,
test.strictEqual(remoteName, eventName,
'event name must be equal to the emitted one');
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

'event name must be equal to the emitted one');
test.strictDeepEqual(event.remoteEventArgs, args,
test.strictDeepEqual(remoteArgs, args,
'event arguments must be equal to the passed ones');
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

test.strictEqual(event.interfaceName, iface,
server.getClients()[0].on('event',
(interfaceName, remoteName, remoteArgs) => {
test.strictEqual(interfaceName, iface,
'event interface must match');
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

'event interface must match');
test.strictEqual(event.remoteEventName, eventName,
test.strictEqual(remoteName, eventName,
'event name must be equal to the emitted one');
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

'event name must be equal to the emitted one');
test.strictDeepEqual(event.remoteEventArgs, args,
test.strictDeepEqual(remoteArgs, args,
'event arguments must be equal to the passed ones');
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@aqrln aqrln removed the test label Jun 19, 2017
Copy link
Member

@belochub belochub left a comment

Choose a reason for hiding this comment

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

LGTM with a small nit: this PR doesn't really "optimize" connection events, it just avoids emitting all of the unused events. May you please update the name and commit message accordingly?

Copy link
Member

@nechaido nechaido left a comment

Choose a reason for hiding this comment

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

LGTM pending requested changes.

@lundibundi
Copy link
Member Author

@belochub it also reuses same error callback, removes unneded data from jstp event and replaces callbackForUnknownPacket with 'rejectPacket', should we really just call this one 'remove redundant events'?

@belochub
Copy link
Member

@lundibundi, I didn't say that we should call it "remove redundant events".

@lundibundi
Copy link
Member Author

@belochub I just suggested a name that will present that this PR removes those events, what is your suggestion?

@belochub
Copy link
Member

@lundibundi, I am sorry, I misunderstood your comment, to me it looked like you disagree with the idea of renaming this at all.
In my opinion, a better name for this could be "avoid emitting unused events", but it isn't perfect as well.

@aqrln
Copy link
Member

aqrln commented Jun 21, 2017

The current commit message is fine since the PR does not only vanish redundant events, but also performs various other performance-related optimization (e.g., avoiding creation of extra closure in order to emit 'error' event in callMethod()) and the removal of unnecessary events is explicitly stated in the full commit message.

aqrln pushed a commit that referenced this pull request Jun 21, 2017
* Remove unnecessary events like 'handshake', 'call',
  'handshakeRequest'.
* Replace 'callbackForUnknownPacket' with _rejectPacket().
* Change signature of connection 'event' (remote event), now it contains
  interfaceName, eventName, eventArgs.
* Avoid creating extra closures to conditionally emit the 'error' event
  in callbacks instantiated inside callPacket().

Fixes: #49
PR-URL: #222
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Dmytro Nechai <nechaido@gmail.com>
@aqrln
Copy link
Member

aqrln commented Jun 21, 2017

Landed in 637bb40.

@aqrln aqrln closed this Jun 21, 2017
@aqrln aqrln deleted the optimize-connection-events branch June 21, 2017 06:56
@aqrln
Copy link
Member

aqrln commented Jun 21, 2017

@belochub please let me know if I was too fast on this and I should have waited for your reply.

belochub pushed a commit that referenced this pull request Jan 22, 2018
* Remove unnecessary events like 'handshake', 'call',
  'handshakeRequest'.
* Replace 'callbackForUnknownPacket' with _rejectPacket().
* Change signature of connection 'event' (remote event), now it contains
  interfaceName, eventName, eventArgs.
* Avoid creating extra closures to conditionally emit the 'error' event
  in callbacks instantiated inside callPacket().

Fixes: #49
PR-URL: #222
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Dmytro Nechai <nechaido@gmail.com>
belochub pushed a commit that referenced this pull request Jan 22, 2018
* Remove unnecessary events like 'handshake', 'call',
  'handshakeRequest'.
* Replace 'callbackForUnknownPacket' with _rejectPacket().
* Change signature of connection 'event' (remote event), now it contains
  interfaceName, eventName, eventArgs.
* Avoid creating extra closures to conditionally emit the 'error' event
  in callbacks instantiated inside callPacket().

Fixes: #49
PR-URL: #222
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Dmytro Nechai <nechaido@gmail.com>
belochub added a commit that referenced this pull request Jan 22, 2018
This is a new and shiny first major release for `metarhia-jstp`.
Changes include API refactoring and improvements, implementations of
CLI, sessions, and application versions, native addon build optimizations,
lots of bug fixes, test coverage increase, and other, less notable changes.

This release also denotes the bump of the protocol version to v1.0.
The only difference from the previous version of the protocol is that
"old" heartbeat messages (`{}`) are now deprecated and `ping`/`pong`
messages must be used for this purpose instead.

Notable changes:

 * **src,build:** improve the native module subsystem
   *(Alexey Orlenko)*
   [#36](#36)
   **\[semver-minor\]**
 * **build:** compile in ISO C++11 mode
   *(Alexey Orlenko)*
   [#37](#37)
   **\[semver-minor\]**
 * **build:** improve error handling
   *(Alexey Orlenko)*
   [#40](#40)
   **\[semver-minor\]**
 * **lib:** refactor record-serialization.js
   *(Alexey Orlenko)*
   [#41](#41)
   **\[semver-minor\]**
 * **protocol:** change the format of handshake packets
   *(Alexey Orlenko)*
   [#54](#54)
   **\[semver-major\]**
 * **parser:** remove special case for '\0' literal
   *(Mykola Bilochub)*
   [#68](#68)
   **\[semver-major\]**
 * **client:** drop redundant callback argument
   *(Alexey Orlenko)*
   [#104](#104)
   **\[semver-major\]**
 * **client:** handle errors in connectAndInspect
   *(Alexey Orlenko)*
   [#105](#105)
   **\[semver-major\]**
 * **socket,ws:** use socket.destroy() properly
   *(Alexey Orlenko)*
   [#84](#84)
   **\[semver-major\]**
 * **cli:** add basic implementation
   *(Mykola Bilochub)*
   [#107](#107)
   **\[semver-minor\]**
 * **connection:** fix error handling in optional cbs
   *(Alexey Orlenko)*
   [#147](#147)
   **\[semver-major\]**
 * **lib:** change event signature
   *(Denys Otrishko)*
   [#187](#187)
   **\[semver-major\]**
 * **lib:** add address method to Server
   *(Denys Otrishko)*
   [#190](#190)
   **\[semver-minor\]**
 * **lib:** optimize connection events
   *(Denys Otrishko)*
   [#222](#222)
   **\[semver-major\]**
 * **lib:** refactor server and client API
   *(Denys Otrishko)*
   [#209](#209)
   **\[semver-major\]**
 * **lib,src:** rename term packet usages to message
   *(Denys Otrishko)*
   [#270](#270)
   **\[semver-major\]**
 * **lib:** emit events about connection messages
   *(Denys Otrishko)*
   [#252](#252)
   **\[semver-minor\]**
 * **connection:** make callback method private
   *(Alexey Orlenko)*
   [#306](#306)
   **\[semver-major\]**
 * **lib:** implement sessions
   *(Mykola Bilochub)*
   [#289](#289)
   **\[semver-major\]**
 * **connection:** use ping-pong instead of heartbeat
   *(Dmytro Nechai)*
   [#303](#303)
   **\[semver-major\]**
@belochub belochub mentioned this pull request Jan 22, 2018
belochub added a commit that referenced this pull request Jan 23, 2018
This is a new and shiny first major release for `metarhia-jstp`.
Changes include API refactoring and improvements, implementations of
CLI, sessions, and application versions, native addon build optimizations,
lots of bug fixes, test coverage increase, and other, less notable changes.

This release also denotes the bump of the protocol version to v1.0.
The only difference from the previous version of the protocol is that
"old" heartbeat messages (`{}`) are now deprecated and `ping`/`pong`
messages must be used for this purpose instead.

Notable changes:

 * **src,build:** improve the native module subsystem
   *(Alexey Orlenko)*
   [#36](#36)
   **\[semver-minor\]**
 * **build:** compile in ISO C++11 mode
   *(Alexey Orlenko)*
   [#37](#37)
   **\[semver-minor\]**
 * **build:** improve error handling
   *(Alexey Orlenko)*
   [#40](#40)
   **\[semver-minor\]**
 * **lib:** refactor record-serialization.js
   *(Alexey Orlenko)*
   [#41](#41)
 * **parser:** fix a possible memory leak
   *(Alexey Orlenko)*
   [#44](#44)
   **\[semver-minor\]**
 * **protocol:** change the format of handshake packets
   *(Alexey Orlenko)*
   [#54](#54)
   **\[semver-major\]**
 * **parser:** make parser single-pass
   *(Mykola Bilochub)*
   [#61](#61)
 * **parser:** remove special case for '\0' literal
   *(Mykola Bilochub)*
   [#68](#68)
   **\[semver-major\]**
 * **parser:** fix bug causing node to crash
   *(Mykola Bilochub)*
   [#75](#75)
 * **client:** drop redundant callback argument
   *(Alexey Orlenko)*
   [#104](#104)
   **\[semver-major\]**
 * **client:** handle errors in connectAndInspect
   *(Alexey Orlenko)*
   [#105](#105)
   **\[semver-major\]**
 * **socket,ws:** use socket.destroy() properly
   *(Alexey Orlenko)*
   [#84](#84)
   **\[semver-major\]**
 * **cli:** add basic implementation
   *(Mykola Bilochub)*
   [#107](#107)
   **\[semver-minor\]**
 * **connection:** fix error handling in optional cbs
   *(Alexey Orlenko)*
   [#147](#147)
   **\[semver-major\]**
 * **test:** add JSON5 specs test suite
   *(Alexey Orlenko)*
   [#158](#158)
 * **lib:** change event signature
   *(Denys Otrishko)*
   [#187](#187)
   **\[semver-major\]**
 * **lib:** add address method to Server
   *(Denys Otrishko)*
   [#190](#190)
   **\[semver-minor\]**
 * **parser:** implement NaN and Infinity parsing
   *(Mykola Bilochub)*
   [#201](#201)
 * **parser:** improve string parsing performance
   *(Mykola Bilochub)*
   [#220](#220)
 * **lib:** optimize connection events
   *(Denys Otrishko)*
   [#222](#222)
   **\[semver-major\]**
 * **lib:** refactor server and client API
   *(Denys Otrishko)*
   [#209](#209)
   **\[semver-major\]**
 * **lib,src:** rename term packet usages to message
   *(Denys Otrishko)*
   [#270](#270)
   **\[semver-major\]**
 * **lib:** emit events about connection messages
   *(Denys Otrishko)*
   [#252](#252)
   **\[semver-minor\]**
 * **lib:** implement API versioning
   *(Denys Otrishko)*
   [#231](#231)
   **\[semver-minor\]**
 * **lib:** allow to set event handlers in application
   *(Denys Otrishko)*
   [#286](#286)
   **\[semver-minor\]**
 * **lib:** allow to broadcast events from server
   *(Denys Otrishko)*
   [#287](#287)
   **\[semver-minor\]**
 * **connection:** make callback method private
   *(Alexey Orlenko)*
   [#306](#306)
   **\[semver-major\]**
 * **lib:** implement sessions
   *(Mykola Bilochub)*
   [#289](#289)
   **\[semver-major\]**
 * **connection:** use ping-pong instead of heartbeat
   *(Dmytro Nechai)*
   [#303](#303)
   **\[semver-major\]**
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.

4 participants