You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/11/10 04:04:03 UTC

[GitHub] [dubbo-go] wenxuwan commented on pull request #797: Imp: try to fix too many files open error

wenxuwan commented on pull request #797:
URL: https://github.com/apache/dubbo-go/pull/797#issuecomment-724435704


   > @wenxuwan Nice job, and I approve your pull request. But I still have three confusions:
   > 
   > 1. Why you use `cas` + busy waiting instead of a lock to protect the enque of a SPMC queue?
   > 
   > * `cas` + busy waiting:
   > 
   > https://github.com/apache/dubbo-go/blob/e320f3f7411bd50c519be161a241e6a6f7387031/protocol/dubbo/client.go#L273-L285
   > 
   > * lock:
   > 
   > ```go
   >  	lock()
   >  	c.pool.poolQueue.pushHead(conn) 
   >  	c.pool.ch <- struct{}{}
   >  	unlock()
   > ```
   > 
   > 1. Why you choose the SPMC queue instead of MPMC queue?
   > 
   > * You can find a lock-free implementation of MPMC in [smallnest/queue](https://github.com/smallnest/queue/blob/master/lockfree_queue.go).
   > 
   > 1. Why you use channel + queue instead of only one channel to implement connection pool?
   > 
   > * I think you can put connection into a channel directly, but I'm not sure. Codes may like:
   > 
   > ```go
   > func (p *gettyRPCClientPool) get(protocol, addr string) {
   >     once.Do(
   >         func() {
   >                p.ch = make(chan *gettyRPCClient, p.maxSize)
   > 		for i := 0; i < p.maxSize; i++ {
   > 			p.ch <- nil
   > 		}
   >         }
   >     )
   >     
   >     conn := <- p.ch
   >     if conn == nil {
   >         return newGettyRPCClientConn(p, protocol, addr)
   >     } 
   >     return conn
   > }
   > 
   > func (p *gettyRPCClientPool) put(conn *gettyRPCClient) {
   >     p.ch <- conn
   > }
   > ```
   
   @gaoxinge ,Thank you for your careful review。
   
   Why you use cas + busy waiting instead of a lock to protect the enque of a SPMC queue?
   
   I just want to use atomic instead lock, maybe there is no big difference in their performance with sleep.
   
   
   Why you choose the SPMC queue instead of MPMC queue?
   
   I'am not familiar with MPMC queue, i will read the code you provided in the comments. 
   
   
   Why you use channel + queue instead of only one channel to implement connection pool?
   
   This is a good question. In my opinion, use signal channel it is ok, but there is such a scene,for example, maxSize is three, When the three tasks come, will create three new conns. Then task1 and task2 failed, task3  success. Now the value in chan should be nil, nil, conn. when new task come, it will create new connections although there have available conn. So in my code ,the queue used for store available conn, channel used to control the number of concurrent tasks.
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org