Does the Dial of golang grpc need Close? in the IM type and micro-service architecture?

problem description

in the actual development of golang, whether the Dial, of grpc needs to be closed or not, it can be done in init () if it does not need to be closed. It is better to keep the connection pool long when the connection is closed frequently.

related codes

func init() {
    once.Do(func() {
    var err error
    conn, err = grpc.Dial(config.ServerURL, grpc.WithInsecure())
      if err != nil {
      logger.Err(err, "Gateway Dial ")
      }
      //grpcconncloseconnect
      //tcp
      //deferinit()
    //defer conn.Close()
   })
}
Jul.16,2021

if you don't need to close it, you can put it in a pool and take it when you use it.
there are two situations at this time.
the first one is that you can get it from the pool, then use it, and put it back after use.
the second case is that it cannot be obtained. At this time, there is one new, but put it back after using it. This time is divided into two cases

.
  1. the pool is already full and is closed at this time.
  2. the pool is not full, put it in the pool.

that's about it. A lot of grpc plugin is implemented in this way, so you can check it out.
I hope I can give you some ideas.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bc9f3b-309d9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bc9f3b-309d9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?