mongoid_connection_pool 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# MongoidConnectionPool
|
2
2
|
|
3
|
-
If you
|
4
|
-
|
3
|
+
If you ever use Mongoid in a threaded environment such as Sidekiq with Rubinius
|
4
|
+
or JRuby you will quickly find out that Mongoid does not handle DB connections
|
5
|
+
well.
|
5
6
|
|
6
7
|
Mongoid by default gives every thread it's own database connection and doesn't
|
7
8
|
clean up after itself, so these connections remain open.
|
8
9
|
MongoDB will quickly become overloaded and you will no longer be able to connect.
|
9
|
-
Often times MongoDB will also
|
10
|
+
Often times MongoDB itself will also crash.
|
10
11
|
|
11
12
|
This gem monkey patches Mongoid (>= 3.1 < 4.0) to add connection pooling.
|
12
13
|
We take over how Mongoid handles it's connections, so there is nothing you need
|
@@ -18,7 +19,7 @@ implementation of connection pooling.
|
|
18
19
|
This is all well and good but it is still as of yet to be released, and won't
|
19
20
|
be supported on Mongoid versions < 4.0 (also unreleased).
|
20
21
|
|
21
|
-
This monkey
|
22
|
+
This monkey patch passes all of Mongoid's specs.
|
22
23
|
|
23
24
|
## Installation
|
24
25
|
|
@@ -38,6 +39,31 @@ Or install it yourself as:
|
|
38
39
|
|
39
40
|
Just require mongoid_connection_pool AFTER Mongoid. That's it. Easy-peasy.
|
40
41
|
|
42
|
+
Configure it for your environment with the following options:<br />
|
43
|
+
session_pool_size: The max number of DB connections you want to have in the pool<br />
|
44
|
+
session_checkout_timeout: Time for a thread to wait for a connection (in seconds) before timing out<br />
|
45
|
+
session_reap_frequency: Time, in seconds, for the session to reap unused but checked out sessions
|
46
|
+
```ruby
|
47
|
+
Mongoid.configure do |config|
|
48
|
+
config.session_pool_size = 5
|
49
|
+
config.session_checkout_timeout = 3
|
50
|
+
config.session_reap_frequency = 3
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
You can also take advantage of Mongoid.with_session method.
|
55
|
+
This is similar to ActiveRecords 'with_connection'
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Mongoid.with_session do
|
59
|
+
# stuff
|
60
|
+
end
|
61
|
+
```
|
62
|
+
With this you are explicitly checking out a connection and checking it back in
|
63
|
+
once complete.
|
64
|
+
|
65
|
+
You also no longer need to use Kiqstand, the Sidekiq Middleware for Mongoid.
|
66
|
+
|
41
67
|
## Contributing
|
42
68
|
|
43
69
|
1. Fork it
|
@@ -129,6 +129,7 @@ module Mongoid
|
|
129
129
|
|
130
130
|
def clear(thread=nil)
|
131
131
|
if thread
|
132
|
+
disconnect(thread)
|
132
133
|
@reserved_sessions.delete(thread) if session_for(thread)
|
133
134
|
@sessions.pop
|
134
135
|
else
|
@@ -139,6 +140,19 @@ module Mongoid
|
|
139
140
|
@reserved_sessions
|
140
141
|
end
|
141
142
|
|
143
|
+
def disconnect(thread=Thread.current)
|
144
|
+
synchronize do
|
145
|
+
@session_pool.try(:each) do |name, pool|
|
146
|
+
if thread
|
147
|
+
pool.session_for(thread).try(:disconnect)
|
148
|
+
else
|
149
|
+
pool.sessions.try(:each) { |session| session.disconnect }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
true
|
154
|
+
end
|
155
|
+
|
142
156
|
def checkin_from_thread(thread)
|
143
157
|
checkin @reserved_sessions[thread]
|
144
158
|
true
|
@@ -22,11 +22,17 @@ module Mongoid
|
|
22
22
|
@session_pool[name]
|
23
23
|
end
|
24
24
|
|
25
|
-
def disconnect
|
25
|
+
def disconnect(thread=Thread.current)
|
26
26
|
synchronize do
|
27
|
-
session_pool.each
|
28
|
-
|
27
|
+
@session_pool.try(:each) do |name, pool|
|
28
|
+
if thread
|
29
|
+
pool.session_for(thread).try(:disconnect)
|
30
|
+
else
|
31
|
+
pool.sessions.try(:each) { |session| session.disconnect }
|
32
|
+
end
|
33
|
+
end
|
29
34
|
end
|
35
|
+
true
|
30
36
|
end
|
31
37
|
|
32
38
|
def with_name(name)
|
metadata
CHANGED
@@ -1,71 +1,76 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_connection_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Brian Goff
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
|
-
prerelease: false
|
16
|
-
type: :development
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.3'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
|
-
prerelease: false
|
30
|
-
type: :development
|
31
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
32
34
|
requirements:
|
33
35
|
- - ! '>='
|
34
36
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
36
|
-
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
37
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ! '>='
|
40
44
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
42
|
-
MA==
|
45
|
+
version: '0'
|
43
46
|
- !ruby/object:Gem::Dependency
|
44
47
|
name: rspec
|
45
|
-
prerelease: false
|
46
|
-
type: :development
|
47
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
48
50
|
requirements:
|
49
51
|
- - ! '>='
|
50
52
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
52
|
-
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
53
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
54
58
|
requirements:
|
55
59
|
- - ! '>='
|
56
60
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
MA==
|
61
|
+
version: '0'
|
59
62
|
- !ruby/object:Gem::Dependency
|
60
63
|
name: mongoid
|
61
|
-
prerelease: false
|
62
|
-
type: :runtime
|
63
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
64
66
|
requirements:
|
65
67
|
- - ~>
|
66
68
|
- !ruby/object:Gem::Version
|
67
69
|
version: 3.1.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
68
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
69
74
|
requirements:
|
70
75
|
- - ~>
|
71
76
|
- !ruby/object:Gem::Version
|
@@ -90,33 +95,34 @@ files:
|
|
90
95
|
- lib/mongoid_connection_pool/version.rb
|
91
96
|
- mongoid_connection_pool.gemspec
|
92
97
|
- spec/session_pool_spec.rb
|
98
|
+
- spec/sessions_spec.rb
|
93
99
|
- spec/spec_helper.rb
|
94
100
|
homepage: http://www.github.com/cpuguy83/mongoid_connection_pool
|
95
101
|
licenses:
|
96
102
|
- MIT
|
97
|
-
metadata: {}
|
98
103
|
post_install_message:
|
99
104
|
rdoc_options: []
|
100
105
|
require_paths:
|
101
106
|
- lib
|
102
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
103
109
|
requirements:
|
104
110
|
- - ! '>='
|
105
111
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
107
|
-
MA==
|
112
|
+
version: '0'
|
108
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
109
115
|
requirements:
|
110
116
|
- - ! '>='
|
111
117
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
113
|
-
MA==
|
118
|
+
version: '0'
|
114
119
|
requirements: []
|
115
120
|
rubyforge_project:
|
116
|
-
rubygems_version:
|
121
|
+
rubygems_version: 1.8.24
|
117
122
|
signing_key:
|
118
|
-
specification_version:
|
123
|
+
specification_version: 3
|
119
124
|
summary: Provides connection pooling for Mongoid
|
120
125
|
test_files:
|
121
126
|
- spec/session_pool_spec.rb
|
127
|
+
- spec/sessions_spec.rb
|
122
128
|
- spec/spec_helper.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
YzQ5Y2MxMTY1YmMyODFjNTI0YzQ5MDQ4NjhkM2VmNDRiYTExYjY2ZA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTMzZTMwYzZjNTlkYTcyMGZjYWJhMTI3ZmNkZDUyNGEwYTMwMzAwNA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MzRhMmIwYmY5NmI2YzQ0YzExNzAwMTE4NjA5MjRlMTQ2OTAxMDRhOTU1MzMy
|
10
|
-
ZDA2ZmYzMTc4OGY2NGRmNmVjYWM2MWNmYWUzYWU0YjU5YmI2ZjA5OWM4ZWMw
|
11
|
-
Y2RmNDNjMGExNTAwYTlkZWFhMDBlNzY0MzkzMTI1MmZlNzEzZjk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjI1NTkyODUwODQyODgxZTJiMTFjMzViNWIwM2M5OWZjMWQ5YWZmYWExM2Yx
|
14
|
-
MGQzZjEwYjJlMGJjMjM0NjE5ZGYwNTc3YzA5MjEwOWUzZjEyYmIzMWJkZGJm
|
15
|
-
ZGYzNmRiMWQ5ZDhlNDMzN2UxOThhYzJiNmU5ODcyMzYwZTVjMDU=
|