question about promise pipelining in q-connection

40 views
Skip to first unread message

Darren Cruse

unread,
Jan 26, 2014, 11:57:59 AM1/26/14
to q-con...@googlegroups.com
Wanting to understand promise pipelining in q-connection better this morning I read through this from the E documentation and tried to implement the same pattern in q-connection.  

In both the above doc and in q-connection's reference to the "secret sauce" I was thinking that in e.g. something like:

var t1 = remote.get('X').invoke('a');

I thought client side q-connection would send the message for the "get" and immediately send the message for the "invoke" before the response for the "get" had come back.

Do I understand that right?

I ask because in my q-connection example I've tried different things but I can't seem to get it to send all the requests from the client up front.

I'm not sure if I'm misunderstanding something, or coding it wrong...

If it helps to, at the moment I've got this in my server.js:

  var X = {
    a: function () {
      return {      
        c: function (z) {
          return z * z;
        }
      };
    }
  };

  var Y = {
    b: function () {
      return 2;
    }
  };

  var remoted = { X: X, Y: Y };

  var remote = Connection(port, remoted);

And this in my client.js:

  var remote = Connection(port);
 
  var x = remote.get('X');
  var y = remote.get('Y');
  var t1 = x.invoke('a');
  var t2 = y.invoke('b');
  var t3 = t1.invoke('c', t2);
  t3.then(function (result) {
    console.log('client result:', result);
  });

This blows up in the server when it's call with undefined as the argument to c.  I guess because I've passed the promise for t2 on the client before it's resolved.

(I'm fuzzy I was thinking that was part of what promise pipelining was saying I should be able to do?)

One fix I found to make it function is to do a then for t2 like this:

  var remote = Connection(port);

  var x = remote.get('X');
  var y = remote.get('Y');
  var t1 = x.invoke('a');
  var t2P = y.invoke('b');
  t2P.then(function (t2) {
    var t3 = t1.invoke('c', t2);
    t3.then(function (result) {
      console.log(hrtime() + ' client result:', result);
    });
  });

But like I said my even bigger question is why isn't the "secret sauce" kicking in and at least sending like the remote.get('X').invoke('a') and remote.get('Y').invoke('b') messages all through to the server up front all at once.

(I appreciate that this technique is speaking to the excessive "chattiness" people criticized e.g. CORBA as having had right - so I'd really like to understand this better, and how to use q-connection better).

Sorry for being a pest,

Darren


  

Darren Cruse

unread,
Jan 26, 2014, 12:33:42 PM1/26/14
to q-con...@googlegroups.com
If it helps btw these are the q-connection messages being sent and received in time (that first number is time in microseconds):

var x = remote.get('X'); ->
108891138.72 client sent: {"type":"send","to":"","from":"BE4E81B9-1DAB-474C-C7722C757340","op":"get","args":["X"]}
var y = remote.get('Y'); ->
108891821.169 client sent: {"type":"send","to":"","from":"9E943CAE-A4B3-43C2-7CD523436C30","op":"get","args":["Y"]}
108893626.246 server got: {"type":"send","to":"","from":"BE4E81B9-1DAB-474C-C7722C757340","op":"get","args":["X"]}
108895969.092 server sent: {"type":"resolve","to":"BE4E81B9-1DAB-474C-C7722C757340","resolution":{"a":{"@":"7CA7CAB6-140E-456B-F15E735DA940","type":"function"}}}
108897070.202 server got: {"type":"send","to":"","from":"9E943CAE-A4B3-43C2-7CD523436C30","op":"get","args":["Y"]}
108897519.647 server sent: {"type":"resolve","to":"9E943CAE-A4B3-43C2-7CD523436C30","resolution":{"b":{"@":"80DD09F5-5104-4A09-F16A5221997F","type":"function"}}}
<- var x = remote.get('X');
108898076.891 client got: {"type":"resolve","to":"BE4E81B9-1DAB-474C-C7722C757340","resolution":{"a":{"@":"7CA7CAB6-140E-456B-F15E735DA940","type":"function"}}}
var t1 = x.invoke('a'); ->
108899336.804 client sent: {"type":"send","to":"7CA7CAB6-140E-456B-F15E735DA940","from":"AF68A0B2-1A8D-46D2-8E9C64D9D9B7","op":"apply","args":[{"%":"undefined"},[]]}
108899718.75 server got: {"type":"send","to":"7CA7CAB6-140E-456B-F15E735DA940","from":"AF68A0B2-1A8D-46D2-8E9C64D9D9B7","op":"apply","args":[{"%":"undefined"},[]]}
<- var y = remote.get('Y');
108899937.172 client got: {"type":"resolve","to":"9E943CAE-A4B3-43C2-7CD523436C30","resolution":{"b":{"@":"80DD09F5-5104-4A09-F16A5221997F","type":"function"}}}
108900152.572 server: in a()
108900576.975 server sent: {"type":"resolve","to":"AF68A0B2-1A8D-46D2-8E9C64D9D9B7","resolution":{"c":{"@":"DE103C03-16E2-41AA-0BC699DC9153","type":"function"}}}
var t2P = y.invoke('b'); ->
108900826.517 client sent: {"type":"send","to":"80DD09F5-5104-4A09-F16A5221997F","from":"D0F9271C-079C-49C1-7914663A10BB","op":"apply","args":[{"%":"undefined"},[]]}
<- var t1 = x.invoke('a');
108900963.572 client got: {"type":"resolve","to":"AF68A0B2-1A8D-46D2-8E9C64D9D9B7","resolution":{"c":{"@":"DE103C03-16E2-41AA-0BC699DC9153","type":"function"}}}
108901000.561 server got: {"type":"send","to":"80DD09F5-5104-4A09-F16A5221997F","from":"D0F9271C-079C-49C1-7914663A10BB","op":"apply","args":[{"%":"undefined"},[]]}
108901484.649 server: in b()
108901597.483 server sent: {"type":"resolve","to":"D0F9271C-079C-49C1-7914663A10BB","resolution":2}
<- var t2P = y.invoke('b');
108901770.518 client got: {"type":"resolve","to":"D0F9271C-079C-49C1-7914663A10BB","resolution":2}
var t3 = t1.invoke('c', t2); ->
108902439.639 client sent: {"type":"send","to":"DE103C03-16E2-41AA-0BC699DC9153","from":"5BCC8141-805B-4673-16C6916EF55B","op":"apply","args":[{"%":"undefined"},[2]]}
108902646.258 server got: {"type":"send","to":"DE103C03-16E2-41AA-0BC699DC9153","from":"5BCC8141-805B-4673-16C6916EF55B","op":"apply","args":[{"%":"undefined"},[2]]}
108902976.64 server: in c()
108903089.493 server sent: {"type":"resolve","to":"5BCC8141-805B-4673-16C6916EF55B","resolution":4}
<- var t3 = t1.invoke('c', t2);
108903237.694 client got: {"type":"resolve","to":"5BCC8141-805B-4673-16C6916EF55B","resolution":4}
108903567.24 client result: 4

Darren Cruse

unread,
Feb 3, 2014, 9:20:45 AM2/3/14
to q-con...@googlegroups.com
Been looking at the q-connection code hoping to understand if these messages waiting for each promise to resolve is by design or a bug.

I don't think it's by design unless that diagram in the q-connection readme was illustrating some future roadmap or something.

Assuming it's a bug maybe I should go ahead and submit this as an issue in github.  If people think otherwise let me know.

Thanks,

Darren

Mark Miller

unread,
Feb 3, 2014, 11:30:15 AM2/3/14
to q-con...@googlegroups.com
Hi Darren, please do submit it as an issue. Thanks.


--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Text by me above is hereby placed in the public domain

  Cheers,
  --MarkM
Reply all
Reply to author
Forward
0 new messages