duanchen7703 2018-07-31 02:40
浏览 53
已采纳

优化golang连接池

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题