2018-07-31 02:40
浏览 51


Ask a question about using golang to develop a connection pool to put connections in a buffered channel with get and put operations <-chan and chan <- conn

Currently, there is also a function to check whether the connection is valid at regular intervals. To do this at regular intervals, that is, to take out the check and store it in, but will it affect the normal get and put operation when checking?

Or are there other data structures to recommend?

Thank you very much!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubang4881 2018-07-31 08:38

    ... will it affect the normal get and put operation when checking

    So currently you pop one connection from the channel and check if it's live. While this is being checked, that connection wont be available to other subscribers on that pool channel.

    I guess you're asking if this will affect any concurrent operation at the time you do this check?

    I don't think it will since the 'user' of the pool also has to pop a connection from the channel to use the connection. So a concurrent operation shouldn't occur.

    This, of course depends on you having a 'Put' function that pops the connection from the channel, does a command, then pushes it back onto the channel only once everything is done.

    打赏 评论

相关推荐 更多相似问题