Can multiple Relay\Cluster instances share the same underlying connections? #170
-
|
Hi, I have noticed that when you create two instances of I am wondering if this is by design? Since the Is it up to the consuming application implement its own prefixing mechanism if it wants to ensure that there is only 1 connection per master node? Or is there any possibility of reusing the connections between instances of The more I think about it, the more I think that this should be up to the consuming application and it is by design, but wanted to check to be sure.. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, if the two The reason we don't do multiplexing like that is because of shared state. $rc1 = new Relay\Cluster(NULL, ['localhost:7000']);
$rc2 = new Relay\Cluster(NULL, ['localhost:7000']);
$rc1->multi();
$rc1->set('foo', 'bar');
// We can't use the connection from rc1, since it is in a MULTI state.
$rc2->get('foo');If the two objects are not active at the same time then relay should share these underlying sockets. We have specialized logic in fact to ensure that when an object destructor is invoked we return any connection to an atomic state. If this fails we actually discard the persistent connection. What you're asking for is theoretically possible from a technical perspective, but it would be tricky to get right so that it didn't cause confusion for users. There are a few client libraries that multiplex by default so we could look into this as a feature. Hopefully I that answers your question! |
Beta Was this translation helpful? Give feedback.
Yes, if the two
Relay\Clusterobjects are alive at the same time, they will not share connections. The way Relay stores persistent socket connections is per instance, so in theory each individual connection could be reused by a differentRelay\Clusterobject but not if they are both active at the same time.The reason we don't do multiplexing like that is because of shared state.