walkor / GatewayWorker

Distributed realtime messaging framework based on workerman.
MIT License
1.01k stars 296 forks source link

Questions #19

Closed sm2017 closed 7 years ago

sm2017 commented 7 years ago

1- What is the memory showing in the php index.php status , current using memory? Peak memory?

2- How Gateway (G) , Business worker (B) and Register (R) is connected together? If we have 1 R , 10 G and 20 B , how are connected? and how many connection have R , B and G?

3- If I have a GatewayClient in my BusinessWorker and I use sendToClient OR sendToUid , What happens exactly? If I have 10 Gateway , I think for both command each 10 gateway receive a message

walkor commented 7 years ago

1- the memory showing in the php index.php status is current using memory which is returned by memory_get_usage(true).

2- If we have 1 R , 10 G and 20 B, then R will has 30 connections(10G+20B),every B has 10 connections to G and every G has 20 connections to B.

3- If you have 10 Gateway, sendToClient($client_id, $msg) only one Gateway which hold the $client_id will receive the message. But sendToUid($uid, $message) all of Gateways will receive the message.

sm2017 commented 7 years ago

How can I do this? I want to change sendToUid implementation , and If uid A is connected to gateway 5 and 9 , (We have 10 gateway) and business worker 18 call sendToUid('A', $message) , only the Gateways which hold the uid will receive the message, only G5 and G9

walkor commented 7 years ago

You can use redis to store the mapping between uid and client_id. Store client_id to uid mapping in redis when bindUid($client_id, $uid) called, and in onClose callback remove client_id of the uid from redis. When you want to send data to uid, get all the client_ids from redis, and then call the sendToAll($msg, $client_id_array) method to send the msg to all client_ids of the uid.

sm2017 commented 7 years ago

Hi again

I want to know more about Gateway (G) , Business worker (B) and Register (R)

1- Can we have multiple R in multiple server? and If one of them is stopped , other works 2- Can we have multiple R worker in single server like G and BW? 3- If we have 3 server , and in R is in server 1 , BW and G are in all servers , what happens if , we start all servers , stop server 1 , (I know server 2 and server 3 is working well if no worker reloaded) , then start server 1 (I think server 1 cannot see server 2 and 3 , that means there is no connection from G in server 1 to BW in server 2,3 , Right? if yes , how can I solve it , if no can you explain why?)

walkor commented 7 years ago

1- Multiple Register in one project is not supported. Each project must has only one Register. 2- You can run multiple gateway projects in single server and each project has is's own Register. 3- Server1 server2 server3 will connect each other when server1 started again .

sm2017 commented 7 years ago

I want to use redis to store the mapping between uid and client_id . But I have a big problem Assume I have 3 server and each server have 1 gateway , uid A is connected to server 1 and 2 and we store it in redis , now we have a fail on redis (Redis is down , server 3 cannot connect to redis as a network problem and ... ) , then uid A is connected to server 3 So we cannot update redis , then redis is come back , As you can guess , If we ask redis where is uid A ,it reply server 1 and 2 and we never send message to uid A connected to server 3 , So how can I solve this problem??

walkor commented 7 years ago

I think this is redis's issue for high availability. Redis cluster or master slave may help? I don't know. Just open issue to redis.