“Too many open files”错误与rethinkdb

huangapple go评论74阅读模式
英文:

"Too many open files" error with rethinkdb

问题

我使用了<https://github.com/dancannon/gorethink>提供的golang驱动程序。据我了解,我从未关闭连接并重新连接。我无法关闭连接,因为我不知道如何获取连接。我知道如何获取会话,并开始思考如何获取正确的会话。

所以我的问题是:

  1. 如何修复错误?
  2. 如何关闭连接并重新连接?

编辑:

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

// 如何定义会话:
session, e := r.Connect(r.ConnectOpts{
Address: "localhost:28015",
Database: "database",
MaxActive: 0,
MaxIdle: 0,
// IdleTimeout: time.Minute,
})
//
// 插入
inserts := map[string]interface{}{"something": something, "something1": something1, "something2": something2}
r.Db("database").Table("table").Insert(inserts).RunWrite(session)
//
// 更新
r.Db("database").Table("table").Filter(map[string]interface{}{"parameter": parameter}).Update(map[string]interface{}{"something": somethingMore}).RunWrite(session)
//
// 获取某一行
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

// 池中最大空闲连接数。
MaxIdle int

// 池在给定时间分配的最大连接数。
// 当为零时,池中的连接数没有限制。
MaxActive int

// 在保持空闲状态的持续时间后关闭连接。如果值为零,则不关闭空闲连接。应用程序应将超时设置为小于服务器的超时值。
IdleTimeout time.Duration
// 包含过滤或未导出的字段

}

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

英文:

I used the golang driver provided by <https://github.com/dancannon/gorethink>. It is my understanding that i never close connection and reconnect. I can't close the connection because i don't know how to get the connection. What i know how is to get the session, and starting to think i don't know the right way to get the session.

So my question is:

  1. How to fix the error?
  2. How to close connection and reconnect?

EDIT:

@OneOfOne Not some, basically all of the related code:

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

@neumino:
This is what comes out when i hit 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

I don't know whether this is too low or too high.

@VonC : That's one of the things that i don't get, I can't see how connection is inside the pool:

//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&#39;s timeout.
    IdleTimeout time.Duration
    // contains filtered or unexported fields
}

Or did I just misunderstand what a pool is or what a connection is (or even what a session is)?

答案1

得分: 3

你可以先查看一下当前的限制,也许它设置得过低了?运行ulimit -a来查看你的设置。

如果你需要增加打开文件的数量,可以运行ulimit -n <打开文件的数量>

我在你的defaultStore.go文件中没有看到明显的问题。游标已关闭,连接应该已释放。我快速浏览了一下你的代码,似乎没有创建不必要的会话/连接池,所以我不确定问题出在哪里(或者我可能漏掉了什么?)。

英文:

You can first look at your current limit, maybe it's excessively low? Run ulimit -a to see your settings

If you need to increase the number of open files, you can run ulimit -n &lt;number of open files&gt;.

I don't see any obvious problem in your defaultStore.go file. The cursor are closed, and the connection should be released. I gave a quick look at your code, and it doesn't seem that you create unnecessary sessions/pool, so I'm not sure where is the problem (or maybe I missed something?).

huangapple
  • 本文由 发表于 2014年7月13日 03:41:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/24716642.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定