@@ -32,10 +32,20 @@ type tCertPoolEntry struct {
32
32
client * clientImpl
33
33
}
34
34
35
+ const maxFillerThreads = 5
36
+
35
37
//NewTCertPoolEntry creates a new tcert pool entry
36
38
func newTCertPoolEntry (client * clientImpl , attributes []string ) * tCertPoolEntry {
37
- tCertChannel := make (chan * TCertBlock , client .conf .getTCertBatchSize ()* 2 )
38
- tCertChannelFeedback := make (chan struct {}, client .conf .getTCertBatchSize ()* 2 )
39
+ var tCertChannel chan * TCertBlock
40
+ var tCertChannelFeedback chan struct {}
41
+
42
+ if client .conf .IsMultiChannelEnabled () {
43
+ tCertChannel = make (chan * TCertBlock , client .conf .getTCertBatchSize ()* maxFillerThreads )
44
+ tCertChannelFeedback = make (chan struct {}, maxFillerThreads )
45
+ } else {
46
+ tCertChannel = make (chan * TCertBlock , client .conf .getTCertBatchSize ()* 2 )
47
+ tCertChannelFeedback = make (chan struct {}, client .conf .getTCertBatchSize ()* 2 )
48
+ }
39
49
done := make (chan struct {}, 1 )
40
50
return & tCertPoolEntry {attributes , tCertChannel , tCertChannelFeedback , done , client }
41
51
}
@@ -90,9 +100,11 @@ func (tCertPoolEntry *tCertPoolEntry) GetNextTCert(attributes ...string) (tCertB
90
100
tCertPoolEntry .client .Error ("Failed getting a new TCert. Buffer is empty!" )
91
101
}
92
102
if tCertBlock != nil {
93
- // Send feedback to the filler
94
- tCertPoolEntry .client .Debug ("Send feedback" )
95
- tCertPoolEntry .tCertChannelFeedback <- struct {}{}
103
+ if ! tCertPoolEntry .client .conf .IsMultiChannelEnabled () {
104
+ // Send feedback to the filler
105
+ tCertPoolEntry .client .Debug ("Send feedback" )
106
+ tCertPoolEntry .tCertChannelFeedback <- struct {}{}
107
+ }
96
108
break
97
109
}
98
110
}
@@ -175,14 +187,24 @@ func (tCertPoolEntry *tCertPoolEntry) filler() {
175
187
tCertPoolEntry .client .Debug ("Load unused TCerts...done!" )
176
188
177
189
if ! stop {
178
- ticker := time .NewTicker (1 * time .Second )
190
+ fillerThreads := 0
191
+ var ticker * time.Ticker
192
+ if tCertPoolEntry .client .conf .IsMultiChannelEnabled () {
193
+ ticker = time .NewTicker (200 * time .Millisecond )
194
+ } else {
195
+ ticker = time .NewTicker (1 * time .Second )
196
+ }
179
197
for {
180
198
select {
181
199
case <- tCertPoolEntry .done :
182
200
stop = true
183
201
tCertPoolEntry .client .Debug ("Done signal." )
184
202
case <- tCertPoolEntry .tCertChannelFeedback :
185
- tCertPoolEntry .client .Debug ("Feedback received. Time to check for tcerts" )
203
+ if tCertPoolEntry .client .conf .IsMultiChannelEnabled () {
204
+ fillerThreads --
205
+ } else {
206
+ tCertPoolEntry .client .Debug ("Feedback received. Time to check for tcerts" )
207
+ }
186
208
case <- ticker .C :
187
209
tCertPoolEntry .client .Debug ("Time elapsed. Time to check for tcerts" )
188
210
}
@@ -192,25 +214,39 @@ func (tCertPoolEntry *tCertPoolEntry) filler() {
192
214
break
193
215
}
194
216
195
- if len (tCertPoolEntry .tCertChannel ) < tCertPoolEntry .client .conf .getTCertBatchSize () {
196
- tCertPoolEntry .client .Debugf ("Refill TCert Pool. Current size [%d]." ,
197
- len (tCertPoolEntry .tCertChannel ),
198
- )
217
+ if tCertPoolEntry .client .conf .IsMultiChannelEnabled () {
199
218
200
- var numTCerts = cap (tCertPoolEntry .tCertChannel ) - len (tCertPoolEntry .tCertChannel )
201
- if len (tCertPoolEntry .tCertChannel ) == 0 {
202
- numTCerts = cap (tCertPoolEntry .tCertChannel ) / 10
203
- if numTCerts < 1 {
204
- numTCerts = 1
205
- }
206
- }
219
+ for len (tCertPoolEntry .tCertChannel ) <= tCertPoolEntry .client .conf .getTCertBatchSize ()* (maxFillerThreads - fillerThreads - 1 ) {
220
+ tCertPoolEntry .client .Debugf ("Refill TCert Pool. Current size [%d]." , len (tCertPoolEntry .tCertChannel ))
221
+ numTCerts := tCertPoolEntry .client .conf .getTCertBatchSize ()
207
222
208
- tCertPoolEntry .client .Infof ("Refilling [%d] TCerts." , numTCerts )
223
+ tCertPoolEntry .client .Infof ("Refilling [%d] TCerts." , numTCerts )
224
+ fillerThreads ++
209
225
210
- err := tCertPoolEntry .client .getTCertsFromTCA (calculateAttributesHash (tCertPoolEntry .attributes ), tCertPoolEntry .attributes , numTCerts )
211
- if err != nil {
212
- tCertPoolEntry .client .Errorf ("Failed getting TCerts from the TCA: [%s]" , err )
213
- break
226
+ go func () {
227
+ err := tCertPoolEntry .client .getTCertsFromTCA (calculateAttributesHash (tCertPoolEntry .attributes ), tCertPoolEntry .attributes , numTCerts )
228
+ if err != nil {
229
+ tCertPoolEntry .client .Errorf ("Failed getting TCerts from the TCA: [%s]" , err )
230
+ }
231
+ tCertPoolEntry .tCertChannelFeedback <- struct {}{}
232
+ }()
233
+ }
234
+ } else {
235
+ if len (tCertPoolEntry .tCertChannel ) < tCertPoolEntry .client .conf .getTCertBatchSize () {
236
+ tCertPoolEntry .client .Debugf ("Refill TCert Pool. Current size [%d]." , len (tCertPoolEntry .tCertChannel ))
237
+ var numTCerts = cap (tCertPoolEntry .tCertChannel ) - len (tCertPoolEntry .tCertChannel )
238
+ if len (tCertPoolEntry .tCertChannel ) == 0 {
239
+ numTCerts = cap (tCertPoolEntry .tCertChannel ) / 10
240
+ if numTCerts < 1 {
241
+ numTCerts = 1
242
+ }
243
+ }
244
+ tCertPoolEntry .client .Infof ("Refilling [%d] TCerts." , numTCerts )
245
+
246
+ err := tCertPoolEntry .client .getTCertsFromTCA (calculateAttributesHash (tCertPoolEntry .attributes ), tCertPoolEntry .attributes , numTCerts )
247
+ if err != nil {
248
+ tCertPoolEntry .client .Errorf ("Failed getting TCerts from the TCA: [%s]" , err )
249
+ }
214
250
}
215
251
}
216
252
}
0 commit comments