Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
52ee85e7
Commit
52ee85e7
authored
Sep 30, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize Redis pool in single-threaded context
This side-steps the need for mutexes and whatnot.
parent
7d48778c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
18 deletions
+9
-18
config/initializers/7_redis.rb
config/initializers/7_redis.rb
+3
-0
lib/gitlab/redis.rb
lib/gitlab/redis.rb
+6
-18
No files found.
config/initializers/7_redis.rb
0 → 100644
View file @
52ee85e7
# Make sure we initialize a Redis connection pool before Sidekiq starts
# multi-threaded execution.
Gitlab
::
Redis
.
with
{
nil
}
lib/gitlab/redis.rb
View file @
52ee85e7
...
@@ -11,13 +11,6 @@ module Gitlab
...
@@ -11,13 +11,6 @@ module Gitlab
DEFAULT_REDIS_URL
=
'redis://localhost:6379'
DEFAULT_REDIS_URL
=
'redis://localhost:6379'
CONFIG_FILE
=
File
.
expand_path
(
'../../config/resque.yml'
,
__dir__
)
CONFIG_FILE
=
File
.
expand_path
(
'../../config/resque.yml'
,
__dir__
)
# To be thread-safe we must be careful when writing the class instance
# variables @_raw_config and @pool. Because @pool depends on @_raw_config we need two
# mutexes to prevent deadlock.
RAW_CONFIG_MUTEX
=
Mutex
.
new
POOL_MUTEX
=
Mutex
.
new
private_constant
:RAW_CONFIG_MUTEX
,
:POOL_MUTEX
class
<<
self
class
<<
self
# Do NOT cache in an instance variable. Result may be mutated by caller.
# Do NOT cache in an instance variable. Result may be mutated by caller.
def
params
def
params
...
@@ -31,24 +24,19 @@ module Gitlab
...
@@ -31,24 +24,19 @@ module Gitlab
end
end
def
with
def
with
if
@pool
.
nil?
@pool
||=
ConnectionPool
.
new
{
::
Redis
.
new
(
params
)
}
POOL_MUTEX
.
synchronize
do
@pool
=
ConnectionPool
.
new
{
::
Redis
.
new
(
params
)
}
end
end
@pool
.
with
{
|
redis
|
yield
redis
}
@pool
.
with
{
|
redis
|
yield
redis
}
end
end
def
_raw_config
def
_raw_config
return
@_raw_config
if
defined?
(
@_raw_config
)
return
@_raw_config
if
defined?
(
@_raw_config
)
RAW_CONFIG_MUTEX
.
synchronize
do
begin
begin
@_raw_config
=
File
.
read
(
CONFIG_FILE
).
freeze
@_raw_config
=
File
.
read
(
CONFIG_FILE
).
freeze
rescue
Errno
::
ENOENT
rescue
Errno
::
ENOENT
@_raw_config
=
false
@_raw_config
=
false
end
end
end
@_raw_config
@_raw_config
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment