Does crossbar have a processes queue?

#1

Hello,

I’ve been doing a project in autobahn js (frontend) and autobahn py (backend). I have a PubSub session (pub in py, sub in js) and a RPC session (call in js, register in py) running. And I’ve put a sleep() function in the python RPC resgister to understand if the PubSub continues working independently from the RPC. Checks out that the PubSub continues working and receives what is meant to receive BUT it doesn’t process it until the RPC gets its result.

More explicitly:

In python:
`def getN(self):
time.sleep(10)
return str(self._n)

`yield self.publish(u’com.example.onimage’,image)

yield self.register(self.getN,u'com.example.getN')

``

In javascript:

`function on_image(args) {
//Do stuff with the image
}

`session.call(‘com.example.getN’).then(
function(result) {
console.log(‘sucess in getting n!’,err);
},
function (err) {
console.log(‘failed to get n!’,err);
}
)

session.subscribe(‘com.example.onimage’,on_image).then (
function(sub) {
console.log(‘subscribed to example image!’);
},
function (err) {
console.log(‘failed to subscribe to topic!’,err);
}
);

``

console.log(‘subscribed to example image!’)

``

This appears ````But the on_image function only executes after the 10 seconds have passed.

I’ve tried putting the RPC and the PubSub in different Realms, and also in different workers (with different ports). But crossbar seems to have this buffer of actions to execute, am I right? If yes, is there a way to avoid it?

I attached the config.json that i was using with 2 different workers if you wanna take a look.

Thanks!

config.json (2.68 KB)

0 Likes

#2

Hi,

        time.sleep(10)

This call (from the standard library) will block the reactor.

You need to use

from autobahn.twisted.util import sleep

yield sleep(10)

instead (or the equivalent) ..

Cheers,
/Tobias

0 Likes

#3

Thank you for the answer.
This was just an example, but so does this mean that if a function takes long to execute, all the other processes will have to wait, even being in different realms and ports?

···

On Thursday, 28 July 2016 16:36:13 UTC, Tobias Oberstein wrote:

Hi,

    time.sleep(10)

This call (from the standard library) will block the reactor.

You need to use

from autobahn.twisted.util import sleep

yield sleep(10)

instead (or the equivalent) …

Cheers,

/Tobias

0 Likes

#4

Thank you for the answer.
This was just an example, but so does this mean that if a function takes
long to execute, all the other processes will have to wait, even being in
different realms and ports?

No, it means two things (in the context of AutobahnPython, which is an _asynchronous_ library - and hence this applies to asynchronous programming using Twisted and asyncio in general - it'll break even if you don't use Autobahn, only pure Twisted/asyncio):

a) you must not block the reactor - by using calls that block on IO
b) if you have a computational intensive function, you have to run that on a background thread

This is how reactor/event driven systems work. It'll be the same for NodeJS etc

Cheers,
/Tobias

···

Am 28.07.2016 um 18:44 schrieb Mariana M:

On Thursday, 28 July 2016 16:36:13 UTC, Tobias Oberstein wrote:

Hi,

        time.sleep(10)

This call (from the standard library) will block the reactor.

You need to use

from autobahn.twisted.util import sleep

yield sleep(10)

instead (or the equivalent) ..

Cheers,
/Tobias

436

0 Likes