rethinkdb出现“打开文件太多”错误

时间:2014-07-12 19:41:08

标签: go rethinkdb

我使用了https://github.com/dancannon/gorethink提供的golang驱动程序。我的理解是,我从不关闭连接并重新连接。我无法关闭连接,因为我不知道如何获得连接。我知道如何参加会议,并开始认为我不知道正确的会议方式。

所以我的问题是:

  1. 如何解决错误?
  2. 如何关闭连接并重新连接?
  3. 编辑:

    @OneOfOne不是一些,基本上所有相关的代码:

    // How i define session:
    session, e := r.Connect(r.ConnectOpts{
        Address:  "localhost:28015",
        Database: "database",
        MaxActive: 0,
        MaxIdle: 0,
        // IdleTimeout: time.Minute,
    })
    //
    // Inserting
    inserts := map[string]interface{}{"something": something, "something1": something1, "something2": something2}
    r.Db("database").Table("table").Insert(inserts).RunWrite(session)
    //
    // Updating
    r.Db("database").Table("table").Filter(map[string]interface{}{"parameter": parameter}).Update(map[string]interface{}{"something" : somethingMore}).RunWrite(session)
    //
    // Get some row
    row, e := r.Db("database").Table("table").Filter(map[string]interface{}{"parameter": parameter}).RunRow(session)
    if e!= nil {
        //error
    }
    

    @neumino: 这是我点击ulimit -a

    时出现的情况
    └─ $ ▶ ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 30419
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 30419
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    

    我不知道这是太低还是太高。

    @VonC:这是我无法获得的事情之一,我无法看到游戏池内的联系:

    //http://godoc.org/github.com/dancannon/gorethink#Pool
    type Pool struct {
        Session *Session
    
        // Maximum number of idle connections in the pool.
        MaxIdle int
    
        // Maximum number of connections allocated by the pool at a given time.
        // When zero, there is no limit on the number of connections in the pool.
        MaxActive int
    
        // Close connections after remaining idle for this duration. If the value
        // is zero, then idle connections are not closed. Applications should set
        // the timeout to a value less than the server's timeout.
        IdleTimeout time.Duration
        // contains filtered or unexported fields
    }
    

    或者我只是误解了游泳池是什么或连接是什么(甚至会话是什么)?

1 个答案:

答案 0 :(得分:3)

你可以先看看你目前的限制,也许它过低了?运行ulimit -a查看您的设置

如果您需要增加打开文件的数量,可以运行ulimit -n <number of open files>

我的defaultStore.go文件中没有任何明显的问题。光标关闭,应该释放连接。我快速查看了你的代码,看起来你没有创建不必要的会话/池,所以我不确定问题出在哪里(或者我错过了什么?)。

相关问题