File tree Expand file tree Collapse file tree 2 files changed +22
-22
lines changed
Expand file tree Collapse file tree 2 files changed +22
-22
lines changed Original file line number Diff line number Diff 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
4444type keyBundle struct {
4545 key common.Comparator
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ limitations under the License.
1717package queue
1818
1919import (
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.
5151type 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) {
7474func (rb * RingBuffer ) Put (item interface {}) error {
7575 var n * node
7676 pos := atomic .LoadUint64 (& rb .queue )
77- // i := 0
77+ i := 0
7878L:
7979 for {
8080 if atomic .LoadUint64 (& rb .disposed ) == 1 {
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
114114func (rb * RingBuffer ) Get () (interface {}, error ) {
115115 var n * node
116116 pos := atomic .LoadUint64 (& rb .dequeue )
117- // i := 0
117+ i := 0
118118L:
119119 for {
120120 if atomic .LoadUint64 (& rb .disposed ) == 1 {
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
You can’t perform that action at this time.
0 commit comments