duai4512 2013-11-14 07:29
浏览 340
已采纳

go / golang + redis打开文件过多错误

I'm using redis in Golang with the Redigo connector (https://github.com/garyburd/redigo) suggested by the Redis website.

I have:

  • After every Dial() I defer a Close()
  • Set fs.file-max = 100000
  • Set vm.overcommit_memory = 1
  • Disabled saving
  • Set maxclients = 100000

I run a high traffic website, and everything runs great for about 10 minutes, from which I get

error: dial tcp 127.0.0.1:6379: too many open files

Then I can't access redis at all from my application.

I see nothing in the redis logs to suggest any errors or problems. What do I do to fix this?

  • 写回答

2条回答 默认 最新

  • ds9567 2013-11-15 01:10
    关注

    I don't know which driver you use but with redigo you can define a number of open connections in a pool, all you have to do then is in every query to redis, first get a client from the pool, then close it, so it goes back to the pool and gets re-used, just like this:

    redisPool = &redis.Pool{
            MaxIdle: 3,
            MaxActive: 10, // max number of connections
            Dial: func() (redis.Conn, error) {
                    c, err := redis.Dial("tcp", ":6379")
                    if err != nil {
                            panic(err.Error())
                    }
                    return c, err
            },
    }
    r := redisPool.Get() // get a client from the pool
    _, err = r.Do("GET one") // use the client
    if err != nil {
            panic(err.Error())
    }
    r.Close() // close the client so the connection gets reused
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误