Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gpt
large_projects
gitlabhq1
Commits
78800193
Commit
78800193
authored
7 years ago
by
Jacob Vosmaer
Browse files
Options
Download
Email Patches
Plain Diff
Recycle Gitaly connections after 1 hour
parent
ceac0ae6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+14
-5
No files found.
lib/gitlab/gitaly_client.rb
View file @
78800193
...
...
@@ -26,9 +26,12 @@ module Gitlab
end
end
CachedConnection
=
Struct
.
new
(
:stub
,
:expire_at
)
SERVER_VERSION_FILE
=
'GITALY_SERVER_VERSION'
.
freeze
MAXIMUM_GITALY_CALLS
=
35
CLIENT_NAME
=
(
Sidekiq
.
server?
?
'gitlab-sidekiq'
:
'gitlab-web'
).
freeze
MAXIMUM_CONNECTION_AGE
=
1
.
hour
MUTEX
=
Mutex
.
new
METRICS_MUTEX
=
Mutex
.
new
...
...
@@ -66,20 +69,26 @@ module Gitlab
def
self
.
stub
(
name
,
storage
)
MUTEX
.
synchronize
do
@stubs
||=
{}
@stubs
[
storage
]
||=
{}
@stubs
[
storage
][
name
]
||=
begin
@connections
||=
{}
@connections
[
storage
]
||=
{}
connection
=
@connections
[
storage
][
name
]
unless
connection
&&
connection
.
expire_at
>
Time
.
now
klass
=
Gitaly
.
const_get
(
name
.
to_s
.
camelcase
.
to_sym
).
const_get
(
:Stub
)
addr
=
address
(
storage
)
addr
=
addr
.
sub
(
%r{^tcp://}
,
''
)
if
URI
(
addr
).
scheme
==
'tcp'
klass
.
new
(
addr
,
:this_channel_is_insecure
)
stub
=
klass
.
new
(
addr
,
:this_channel_is_insecure
)
expire_at
=
Time
.
now
+
(
0.9
+
Random
.
rand
(
0.2
))
*
MAXIMUM_CONNECTION_AGE
connection
=
@connections
[
storage
][
name
]
=
CachedConnection
.
new
(
stub
,
expire_at
)
end
connection
.
stub
end
end
def
self
.
clear_stubs!
MUTEX
.
synchronize
do
@
stub
s
=
nil
@
connection
s
=
nil
end
end
...
...
This diff is collapsed.
Click to expand it.
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