duanjing7651 2017-11-15 00:35 采纳率: 0%
浏览 62
已采纳

有分片的MySQL数据库解决方案时,如何使用go-sql-driver?

Reading this article: http://go-database-sql.org/accessing.html

It says that the sql.DB object is designed to be long-lived and that we should not Open() and Close() databases frequently. But what should I do if I have 10 different MySQL servers and I have sharded them in a way that I have 511 databases in each server for example the way Pinterest shards their data with MySQL?

https://medium.com/@Pinterest_Engineering/sharding-pinterest-how-we-scaled-our-mysql-fleet-3f341e96ca6f

Then would I not need to constantly access new nodes with new databases all the time? As I understand then I have to Open and Close the database connection all the time depending on which node and database I have to access.

It also says that:

If you don’t treat the sql.DB as a long-lived object, you could experience problems such as poor reuse and sharing of connections, running out of available network resources, or sporadic failures due to a lot of TCP connections remaining in TIME_WAIT status. Such problems are signs that you’re not using database/sql as it was designed.

Will this be a problem? How should I solve this issue then?

  • 写回答

1条回答 默认 最新

  • dran0703 2017-11-15 07:09
    关注

    I am also interested in the question. I guess there could be such solution:

    1. Minimize number of idle connection in pool db.SerMaxIdleConns(N)

    2. Make map[serverID]*sql.DB. When you have no such connection - add it to map.

    3. Make Dara more local - so backends usually go to “their” databases. However Pinterest seems not to use it.

    4. Increase number of sockets and files on backend machines so they can keep more open connections.

    5. Provide some reasonable idle timeout so very old unused connections could be closed.

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

报告相同问题?

悬赏问题

  • ¥15 配置FPT报错,该如何处理
  • ¥15 请大家看一下这个代码咋写,一点思路都没有,最好能做一下,不要伪代码,有偿
  • ¥15 有偿请人帮写个安卓系统下禁止装软件及禁止拷入文件的程序
  • ¥100 用 H.265 对音视频硬编码 (CUDA)
  • ¥20 mpich安装完成后出问题
  • ¥15 stm32循迹小车代码问题
  • ¥15 输入一堆单词,使其去重输出
  • ¥15 qc代码,修改和添加东西
  • ¥50 Unity的粒子系统使用shadergraph(内置管线)制作的一个顶点偏移shader,但是粒子模型移动时,顶点也会偏移
  • ¥15 如何用python处理excel的数据(极值标准化)