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
Jérome Perrin
gitlab-ce
Commits
3dd86b83
Commit
3dd86b83
authored
Dec 08, 2014
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use constants instead of getters
parent
4f9a1406
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
26 deletions
+13
-26
lib/gitlab/sidekiq_middleware/memory_killer.rb
lib/gitlab/sidekiq_middleware/memory_killer.rb
+13
-26
No files found.
lib/gitlab/sidekiq_middleware/memory_killer.rb
View file @
3dd86b83
module
Gitlab
module
SidekiqMiddleware
class
MemoryKiller
# Default the RSS limit to 0, meaning the MemoryKiller is disabled
MAX_RSS
=
(
ENV
[
'SIDEKIQ_MEMORY_KILLER_MAX_RSS'
]
||
0
).
to_s
.
to_i
# Give Sidekiq 15 minutes of grace time after exceeding the RSS limit
GRACE_TIME
=
15
*
60
GRACE_TIME
=
(
ENV
[
'SIDEKIQ_MEMORY_KILLER_GRACE_TIME'
]
||
15
*
60
).
to_s
.
to_i
# Wait 30 seconds for running jobs to finish during graceful shutdown
SHUTDOWN_WAIT
=
30
# Create a mutex so that there will be only one thread waiting to shut
# Sidekiq down
SHUTDOWN_WAIT
=
(
ENV
[
'SIDEKIQ_MEMORY_KILLER_SHUTDOWN_WAIT'
]
||
30
).
to_s
.
to_i
# Create a mutex used to ensure there will be only one thread waiting to
# shut Sidekiq down
MUTEX
=
Mutex
.
new
def
call
(
worker
,
job
,
queue
)
yield
current_rss
=
get_rss
return
unless
max_rss
>
0
&&
current_rss
>
max_rss
return
unless
MAX_RSS
>
0
&&
current_rss
>
MAX_RSS
Tread
.
new
do
# Return if another thread is already waiting to shut Sidekiq down
return
unless
MUTEX
.
try_lock
Sidekiq
.
logger
.
warn
"current RSS
#{
current_rss
}
exceeds maximum RSS "
\
"
#{
max_rss
}
"
"
#{
MAX_RSS
}
"
Sidekiq
.
logger
.
warn
"spawned thread that will shut down PID "
\
"
#{
Process
.
pid
}
in
#{
grace_time
}
seconds"
sleep
(
grace_time
)
"
#{
Process
.
pid
}
in
#{
GRACE_TIME
}
seconds"
sleep
(
GRACE_TIME
)
Sidekiq
.
logger
.
warn
"sending SIGUSR1 to PID
#{
Process
.
pid
}
"
Process
.
kill
(
'SIGUSR1'
,
Process
.
pid
)
Sidekiq
.
logger
.
warn
"waiting
#{
shutdown_wait
}
seconds before sending "
\
Sidekiq
.
logger
.
warn
"waiting
#{
SHUTDOWN_WAIT
}
seconds before sending "
\
"SIGTERM to PID
#{
Process
.
pid
}
"
sleep
(
shutdown_wait
)
sleep
(
SHUTDOWN_WAIT
)
Sidekiq
.
logger
.
warn
"sending SIGTERM to PID
#{
Process
.
pid
}
"
Process
.
kill
(
'SIGTERM'
,
Process
.
pid
)
...
...
@@ -45,22 +48,6 @@ module Gitlab
output
.
to_i
end
def
max_rss
@max_rss
||=
ENV
[
'SIDEKIQ_MAX_RSS'
].
to_s
.
to_i
end
def
shutdown_wait
@graceful_shutdown_wait
||=
(
ENV
[
'SIDEKIQ_MEMORY_KILLER_SHUTDOWN_WAIT'
]
||
SHUTDOWN_WAIT
).
to_i
end
def
grace_time
@grace_time
||=
(
ENV
[
'SIDEKIQ_MEMORY_KILLER_GRACE_TIME'
]
||
GRACE_TIME
).
to_i
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