Jump to content

Eureca : a nodeJS remote method invokation library


Ezelia
 Share

Recommended Posts

Hi All,
 
I developped this little library for multiplayer games/applications I write with nodejs
 
the idea is simple : call server side functions from client seamlessly and vice versa .
 
by declaring your methods under Eureca namespace (client or server side) you make them available on the other side (server or client)
 
 
a very simple example :
 
server side

//importsvar http = require('http');var EURECA  = require('eureca').EURECA//variablesvar eureca = new EURECA();var serverNs = eureca.exports;//methodsserverNs.foo = function(param1, param2){     do_something_in_server_side();}serverNs.bar = function(a, {     return operation_with_params(a, ;} 

 
 



client side :

<html>  <head>    <script src="/eureca.js"></script>  </head><body><script> var eureca = new EURECA();   eureca.foo('somevalue', 'other value');  // process server side //bar() returns a value, but since it's asynchronous, we need a callback to get the result eureca.bar(1, 2, function(result) {      console.log('result of server side bar() is ', result); }) </script></body></html> 

 

 
repository and usage example are available here : https://github.com/Ezelia/eureca
 
the library support both standalon and expressJS integration
 
the current release uses sockjs as network library, I found it better than socket.io but I think I'll switch to socket.io since it have a bigger community/support
 
 
any suggestions to enhance the library are welcome :)

Link to comment
Share on other sites

This reminds me of a library that allowed the dev to call PHP methods from inside an Adobe Flex application back the days where flash was cool :D

 

Have already starred your lib and will propably give it a try, soon :)

Thanks for sharing it!

Link to comment
Share on other sites

How looks your message format? I mean how do you recognize what function client called etc. Do you send full name of function over network or did you add some routing system?

I've made my own data message format with everything packed to binary and I'm doing routing depending on type and subtype of message packed into 2 bytes (4 bits - type, 12 bits - subtype), so I don't have that big overhead. I hope you didn't reinvent AMF format :P

Link to comment
Share on other sites

the library is an implementation of JSON RPC with some reductions in fields names so yes the method name is sent.

 

I tested this same library with binary format but benchmarks showed that JSON format is much faster and responsive thant binary, this is due IMO to the fact that JSON is natively implemented in both nodejs and browsers' sides, also, websocket overhead is negligeable while exchanging lot of data.

the library itself can easily be modified to use a binary format but it really don't give any performance gain
 

Link to comment
Share on other sites

Hmm, you might be right when it come to nodeJS since JS binary operations aren't the fastest. I'm using Python on backend and I think binary data is faster to unpack then json, but I didn't make any benchmark. Performance gain would be visible while sending lot of data in real time (fast paced games), mainly because of dataload.  

In your case 

{ "moveCharacterTo": [1234, -4567] }

 

= 36 bytes

 

In binary


<Uint16>type&subtype, <Int16>x, <Int16>y 

 

 

= 6 bytes

Link to comment
Share on other sites

Hmm, it makes difference imo. Packing JSON to binary doesn't change anything, you only add overhead of converting UTF-8 to binary and back to UTF-8 on server (which is huge).

In my version you don't convert whole json string to binary (36 operation or even more if you have char > 127, UTF-8), but only 3 values (3 operations). 

I would like you to benchmark this: send your json string and send binary data, but just values and integer representing ID of function (look at my example post above).

Link to comment
Share on other sites

this is what I actually did (if I understand your example :) )

the problem is not on the server side but in the client side.
when you receive binary data in the client side (the browser) you can't use it as is, you'll have to "parse" your binary data using Javascript code. this parsing is slower than the native JSON.parse() method.

 

binary data may be useful if you have bandwidth problems ... or if one day a binary JSON protocole is natively supported by browsers :)

Link to comment
Share on other sites

What about sending an array of available methods to the client side first and then only transferring the index number instead of the whole method name?

Would bring some vulnerability since one could observe what methods are available. But on the other hand, you would have to transfer much less data with each call.

Link to comment
Share on other sites

this seems to be a good idea :)

about the vulnerability, it's up to the user to secure its calls, in a real game example I authenticate every client first before accepting procedure calls, if a non authentified client try to call a methode the server close the connexion. but this is a specific behaviour, there is so many cases where exposing all methods is not a problem :)

Link to comment
Share on other sites

As far as I can see you are defining the functions on serverside anyways, so they ARE already transferred to client side. So the switch to only sending indexes for method calls should be simple.

 

Another suggestion: you might want to deliver promises when libraries like Q or RSVP are present to prevent a pyramid of doom:

 

var remote = new Eureka();remote.someAsyncFunction(params)      .then(processResponse);function processResponse(returnedValue){    //do something}
Link to comment
Share on other sites

I made a benchmark http://jsperf.com/json-vs-binary-parsing and indeed JSON parse is much faster on client which is a bit odd for me.

 

Question is, what is more important, faster network so I won't have to care about bandwith, or faster CPU so I won't have to care about server cpu speed.

 

it really depend on what game you are making and where you want to host your game server

in all my HTML5 games, most performance issues were in the client side so I tryed to reduce CPU operations as much as possible.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...