Skip to content

Commit 574ae58

Browse files
Modified when tree goes parallel.
1 parent 0fd559b commit 574ae58

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

btree/palm/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const (
3939
apply
4040
)
4141

42-
const multiThreadAt = 1000 // number of keys before we multithread lookups
42+
const multiThreadAt = 400 // number of keys before we multithread lookups
4343

4444
type keyBundle struct {
4545
key common.Comparator

queue/ring.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package queue
1818

1919
import (
20-
//"runtime"
20+
"runtime"
2121
"sync/atomic"
2222
)
2323

@@ -49,13 +49,13 @@ type nodes []*node
4949
// described here: http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
5050
// with some minor additions.
5151
type RingBuffer struct {
52-
_buffer0 [8]uint64
52+
_padding0 [8]uint64
5353
queue uint64
54-
_buffer1 [8]uint64
54+
_padding1 [8]uint64
5555
dequeue uint64
56-
_buffer2 [8]uint64
56+
_padding2 [8]uint64
5757
mask, disposed uint64
58-
_buffer3 [8]uint64
58+
_padding3 [8]uint64
5959
nodes nodes
6060
}
6161

@@ -74,7 +74,7 @@ func (rb *RingBuffer) init(size uint64) {
7474
func (rb *RingBuffer) Put(item interface{}) error {
7575
var n *node
7676
pos := atomic.LoadUint64(&rb.queue)
77-
//i := 0
77+
i := 0
7878
L:
7979
for {
8080
if atomic.LoadUint64(&rb.disposed) == 1 {
@@ -93,13 +93,13 @@ L:
9393
default:
9494
pos = atomic.LoadUint64(&rb.queue)
9595
}
96-
/*
97-
if i == 10000 {
98-
//runtime.Gosched() // free up the cpu before the next iteration
99-
i = 0
100-
} else {
101-
i++
102-
}*/
96+
97+
if i == 10000 {
98+
runtime.Gosched() // free up the cpu before the next iteration
99+
i = 0
100+
} else {
101+
i++
102+
}
103103
}
104104

105105
n.data = item
@@ -114,7 +114,7 @@ L:
114114
func (rb *RingBuffer) Get() (interface{}, error) {
115115
var n *node
116116
pos := atomic.LoadUint64(&rb.dequeue)
117-
//i := 0
117+
i := 0
118118
L:
119119
for {
120120
if atomic.LoadUint64(&rb.disposed) == 1 {
@@ -133,13 +133,13 @@ L:
133133
default:
134134
pos = atomic.LoadUint64(&rb.dequeue)
135135
}
136-
/*
137-
if i == 10000 {
138-
//runtime.Gosched() // free up the cpu before the next iteration
139-
i = 0
140-
} else {
141-
i++
142-
}*/
136+
137+
if i == 10000 {
138+
runtime.Gosched() // free up the cpu before the next iteration
139+
i = 0
140+
} else {
141+
i++
142+
}
143143
}
144144
data := n.data
145145
n.data = nil

0 commit comments

Comments
 (0)