@@ -24,7 +24,7 @@ import { RestApiManager } from './rest_api_manager';
2424const MAX_RETRIES = 3 ;
2525const DEFAULT_BATCH_SIZE = 10 ;
2626const DEFAULT_FLUSH_INTERVAL_MSECS = 1000 ;
27- const DEFAULT_BROWSER_QUEUE_SIZE = 10 ;
27+ const DEFAULT_BROWSER_QUEUE_SIZE = 100 ;
2828const DEFAULT_SERVER_QUEUE_SIZE = 10000 ;
2929
3030/**
@@ -255,19 +255,15 @@ export class OdpEventManager implements IOdpEventManager {
255255 }
256256
257257 // Flush interval occurred & queue has items
258- if ( shouldFlush && this . queueContainsItems ( ) ) {
258+ if ( shouldFlush ) {
259259 // clear the queue completely
260260 this . clearCurrentTimeout ( ) ;
261261
262262 this . state = STATE . PROCESSING ;
263263
264264 while ( this . queueContainsItems ( ) ) {
265- this . makeAndSendBatch ( ) ;
265+ this . makeAndSend1Batch ( ) ;
266266 }
267-
268- this . state = STATE . RUNNING ;
269-
270- this . setNewTimeout ( ) ;
271267 }
272268 // Check if queue has a full batch available
273269 else if ( this . queueHasBatches ( ) ) {
@@ -276,13 +272,12 @@ export class OdpEventManager implements IOdpEventManager {
276272 this . state = STATE . PROCESSING ;
277273
278274 while ( this . queueHasBatches ( ) ) {
279- this . makeAndSendBatch ( ) ;
275+ this . makeAndSend1Batch ( ) ;
280276 }
281-
282- this . state = STATE . RUNNING ;
283-
284- this . setNewTimeout ( ) ;
285277 }
278+
279+ this . state = STATE . RUNNING ;
280+ this . setNewTimeout ( ) ;
286281 }
287282
288283 /**
@@ -309,9 +304,10 @@ export class OdpEventManager implements IOdpEventManager {
309304 * Make a batch and send it to ODP
310305 * @private
311306 */
312- private makeAndSendBatch ( ) : void {
307+ private makeAndSend1Batch ( ) : void {
313308 const batch = new Array < OdpEvent > ( ) ;
314309
310+ // remove a batch from the queue
315311 for ( let count = 0 ; count < this . batchSize ; count += 1 ) {
316312 const event = this . queue . shift ( ) ;
317313 if ( event ) {
@@ -322,6 +318,7 @@ export class OdpEventManager implements IOdpEventManager {
322318 }
323319
324320 if ( batch . length > 0 ) {
321+ // put sending the event on another event loop
325322 setTimeout ( async ( ) => {
326323 let shouldRetry : boolean ;
327324 let attemptNumber = 0 ;
0 commit comments