Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
99c2ec70
Unverified
Commit
99c2ec70
authored
Oct 17, 2021
by
Laurence
Committed by
GitHub
Oct 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: default not to start gr pool limit (#72)
* fix: default not start gr pool * fix: ut
parent
b640a570
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
base_worker_pool.go
sync/base_worker_pool.go
+7
-0
connection_pool.go
sync/connection_pool.go
+5
-0
connection_pool_test.go
sync/connection_pool_test.go
+10
-0
No files found.
sync/base_worker_pool.go
View file @
99c2ec70
...
...
@@ -36,6 +36,7 @@ type WorkerPoolConfig struct {
NumQueues
int
QueueSize
int
Logger
gxlog
.
Logger
Enable
bool
}
// baseWorkerPool is a worker pool with multiple queues.
...
...
@@ -69,6 +70,7 @@ type baseWorkerPool struct {
taskQueues
[]
chan
task
numWorkers
*
atomic
.
Int32
enable
bool
wg
*
sync
.
WaitGroup
}
...
...
@@ -94,6 +96,11 @@ func newBaseWorkerPool(config WorkerPoolConfig) *baseWorkerPool {
taskQueues
:
taskQueues
,
numWorkers
:
new
(
atomic
.
Int32
),
wg
:
new
(
sync
.
WaitGroup
),
enable
:
config
.
Enable
,
}
if
!
config
.
Enable
{
return
p
}
initWg
:=
new
(
sync
.
WaitGroup
)
...
...
sync/connection_pool.go
View file @
99c2ec70
...
...
@@ -45,6 +45,11 @@ func (p *ConnectionPool) Submit(t task) error {
return
perrors
.
New
(
"task shouldn't be nil"
)
}
if
!
p
.
enable
{
go
t
()
return
nil
}
// put the task to a queue using Round Robin algorithm
taskId
:=
atomic
.
AddUint32
(
&
p
.
taskId
,
1
)
select
{
...
...
sync/connection_pool_test.go
View file @
99c2ec70
...
...
@@ -36,6 +36,7 @@ func TestConnectionPool(t *testing.T) {
NumQueues
:
runtime
.
NumCPU
(),
QueueSize
:
10
,
Logger
:
nil
,
Enable
:
true
,
})
var
count
int64
wg
:=
new
(
sync
.
WaitGroup
)
...
...
@@ -60,6 +61,7 @@ func TestConnectionPool(t *testing.T) {
NumQueues
:
1
,
QueueSize
:
0
,
Logger
:
nil
,
Enable
:
true
,
})
wg
:=
new
(
sync
.
WaitGroup
)
...
...
@@ -85,6 +87,7 @@ func TestConnectionPool(t *testing.T) {
NumWorkers
:
runtime
.
NumCPU
(),
NumQueues
:
runtime
.
NumCPU
(),
QueueSize
:
100
,
Enable
:
true
,
Logger
:
nil
,
})
...
...
@@ -102,6 +105,7 @@ func TestConnectionPool(t *testing.T) {
p
:=
NewConnectionPool
(
WorkerPoolConfig
{
NumWorkers
:
0
,
NumQueues
:
runtime
.
NumCPU
(),
Enable
:
true
,
QueueSize
:
100
,
Logger
:
nil
,
})
...
...
@@ -111,6 +115,7 @@ func TestConnectionPool(t *testing.T) {
p
=
NewConnectionPool
(
WorkerPoolConfig
{
NumWorkers
:
1
,
NumQueues
:
0
,
Enable
:
true
,
QueueSize
:
0
,
Logger
:
nil
,
})
...
...
@@ -123,6 +128,7 @@ func TestConnectionPool(t *testing.T) {
NumQueues
:
1
,
QueueSize
:
-
1
,
Logger
:
nil
,
Enable
:
true
,
})
err
=
p
.
Submit
(
func
()
{})
...
...
@@ -134,6 +140,7 @@ func TestConnectionPool(t *testing.T) {
p
:=
NewConnectionPool
(
WorkerPoolConfig
{
NumWorkers
:
1
,
NumQueues
:
1
,
Enable
:
true
,
QueueSize
:
0
,
Logger
:
nil
,
})
...
...
@@ -149,6 +156,7 @@ func TestConnectionPool(t *testing.T) {
NumQueues
:
runtime
.
NumCPU
(),
QueueSize
:
10
,
Logger
:
nil
,
Enable
:
true
,
})
task
,
v
:=
newCountTask
()
...
...
@@ -174,6 +182,7 @@ func TestConnectionPool(t *testing.T) {
NumQueues
:
runtime
.
NumCPU
(),
QueueSize
:
10
,
Logger
:
nil
,
Enable
:
true
,
})
task
,
v
:=
newCountTask
()
...
...
@@ -192,6 +201,7 @@ func BenchmarkConnectionPool(b *testing.B) {
NumWorkers
:
100
,
NumQueues
:
runtime
.
NumCPU
(),
QueueSize
:
100
,
Enable
:
true
,
Logger
:
nil
,
})
...
...
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