Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
1
Merge Requests
1
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
nexedi
gitlab-workhorse
Commits
402e1c9c
Commit
402e1c9c
authored
Mar 03, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unexport newQueue and newQueueMetrics; improve function documentation
parent
07b40d17
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
8 deletions
+23
-8
internal/queueing/queue.go
internal/queueing/queue.go
+12
-4
internal/queueing/queue_test.go
internal/queueing/queue_test.go
+3
-3
internal/queueing/requests.go
internal/queueing/requests.go
+8
-1
No files found.
internal/queueing/queue.go
View file @
402e1c9c
...
...
@@ -23,7 +23,13 @@ type queueMetrics struct {
queueingErrors
*
prometheus
.
CounterVec
}
func
NewQueueMetrics
(
name
string
,
timeout
time
.
Duration
)
*
queueMetrics
{
// newQueueMetrics prepares Prometheus metrics for queueing mechanism
// name specifies name of the queue, used to label metrics with ConstLabel `queue_name`
// Don't call newQueueMetrics twice with the same name argument!
// timeout specifies the timeout of storing a request in queue - queueMetrics
// uses it to calculate histogram buckets for gitlab_workhorse_queueing_waiting_time
// metric
func
newQueueMetrics
(
name
string
,
timeout
time
.
Duration
)
*
queueMetrics
{
waitingTimeBuckets
:=
[]
float64
{
timeout
.
Seconds
()
*
0.01
,
timeout
.
Seconds
()
*
0.05
,
...
...
@@ -121,12 +127,14 @@ type Queue struct {
timeout
time
.
Duration
}
// NewQueue creates a new queue
// newQueue creates a new queue
// name specifies name used to label queue metrics.
// Don't call newQueue twice with the same name argument!
// limit specifies number of requests run concurrently
// queueLimit specifies maximum number of requests that can be queued
// timeout specifies the time limit of storing the request in the queue
// if the number of requests is above the limit
func
N
ewQueue
(
name
string
,
limit
,
queueLimit
uint
,
timeout
time
.
Duration
)
*
Queue
{
func
n
ewQueue
(
name
string
,
limit
,
queueLimit
uint
,
timeout
time
.
Duration
)
*
Queue
{
queue
:=
&
Queue
{
name
:
name
,
busyCh
:
make
(
chan
struct
{},
limit
),
...
...
@@ -134,7 +142,7 @@ func NewQueue(name string, limit, queueLimit uint, timeout time.Duration) *Queue
timeout
:
timeout
,
}
queue
.
queueMetrics
=
N
ewQueueMetrics
(
name
,
timeout
)
queue
.
queueMetrics
=
n
ewQueueMetrics
(
name
,
timeout
)
queue
.
queueingLimit
.
Set
(
float64
(
limit
))
queue
.
queueingQueueLimit
.
Set
(
float64
(
queueLimit
))
queue
.
queueingQueueTimeout
.
Set
(
timeout
.
Seconds
())
...
...
internal/queueing/queue_test.go
View file @
402e1c9c
...
...
@@ -6,7 +6,7 @@ import (
)
func
TestNormalQueueing
(
t
*
testing
.
T
)
{
q
:=
N
ewQueue
(
"queue 1"
,
2
,
1
,
time
.
Microsecond
)
q
:=
n
ewQueue
(
"queue 1"
,
2
,
1
,
time
.
Microsecond
)
err1
:=
q
.
Acquire
()
if
err1
!=
nil
{
t
.
Fatal
(
"we should acquire a new slot"
)
...
...
@@ -31,7 +31,7 @@ func TestNormalQueueing(t *testing.T) {
}
func
TestQueueLimit
(
t
*
testing
.
T
)
{
q
:=
N
ewQueue
(
"queue 2"
,
1
,
0
,
time
.
Microsecond
)
q
:=
n
ewQueue
(
"queue 2"
,
1
,
0
,
time
.
Microsecond
)
err1
:=
q
.
Acquire
()
if
err1
!=
nil
{
t
.
Fatal
(
"we should acquire a new slot"
)
...
...
@@ -44,7 +44,7 @@ func TestQueueLimit(t *testing.T) {
}
func
TestQueueProcessing
(
t
*
testing
.
T
)
{
q
:=
N
ewQueue
(
"queue 3"
,
1
,
1
,
time
.
Second
)
q
:=
n
ewQueue
(
"queue 3"
,
1
,
1
,
time
.
Second
)
err1
:=
q
.
Acquire
()
if
err1
!=
nil
{
t
.
Fatal
(
"we should acquire a new slot"
)
...
...
internal/queueing/requests.go
View file @
402e1c9c
...
...
@@ -9,6 +9,13 @@ import (
const
DefaultTimeout
=
30
*
time
.
Second
// QueueRequests creates a new request queue
// name specifies the name of queue, used to label Prometheus metrics
// Don't call QueueRequests twice with the same name argument!
// h specifies a http.Handler which will handle the queue requests
// limit specifies number of requests run concurrently
// queueLimit specifies maximum number of requests that can be queued
// queueTimeout specifies the time limit of storing the request in the queue
func
QueueRequests
(
name
string
,
h
http
.
Handler
,
limit
,
queueLimit
uint
,
queueTimeout
time
.
Duration
)
http
.
Handler
{
if
limit
==
0
{
return
h
...
...
@@ -17,7 +24,7 @@ func QueueRequests(name string, h http.Handler, limit, queueLimit uint, queueTim
queueTimeout
=
DefaultTimeout
}
queue
:=
N
ewQueue
(
name
,
limit
,
queueLimit
,
queueTimeout
)
queue
:=
n
ewQueue
(
name
,
limit
,
queueLimit
,
queueTimeout
)
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
err
:=
queue
.
Acquire
()
...
...
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