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 01:37:57 UTC

[GitHub] [dubbo-go] gaoxinge edited a comment on pull request #797: Imp: try to fix too many files open error

gaoxinge edited a comment on pull request #797:
URL: https://github.com/apache/dubbo-go/pull/797#issuecomment-724392697


   @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()
   ```
   
   ---
   
   2. 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).
   
   ---
   
   3. 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
   }
   ```


----------------------------------------------------------------
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