@@ -38,22 +38,29 @@ class HttpTransport {
38
38
private int eventsInRetry = 0 ;
39
39
private Object bufferLock = new Object ();
40
40
private Object counterLock = new Object ();
41
- private ExecutorService retryThreadPool ;
42
- private ExecutorService sendThreadPool ;
43
41
44
42
private HttpCall httpCall ;
45
43
private AmplitudeLog logger ;
46
44
private AmplitudeCallbacks callbacks ;
47
45
private long flushTimeout ;
48
46
47
+ // Managed by setters
48
+ private ExecutorService retryThreadPool = Executors .newFixedThreadPool (10 );
49
+
50
+ // The supplyAsyncPool is only used within the sendThreadPool so only when
51
+ // the sendThreadPool is increased will the supplyAsyncPool be more utilized.
52
+ // We are using the supplyAsyncPool rather than the default fork join common
53
+ // pool because the fork join common pool scales with cpu... and we do not
54
+ // want to perform network requests in that small pool.
55
+ private ExecutorService sendThreadPool = Executors .newFixedThreadPool (20 );
56
+ private ExecutorService supplyAsyncPool = Executors .newCachedThreadPool ();
57
+
49
58
HttpTransport (
50
59
HttpCall httpCall , AmplitudeCallbacks callbacks , AmplitudeLog logger , long flushTimeout ) {
51
60
this .httpCall = httpCall ;
52
61
this .callbacks = callbacks ;
53
62
this .logger = logger ;
54
63
this .flushTimeout = flushTimeout ;
55
- retryThreadPool = Executors .newFixedThreadPool (10 );
56
- sendThreadPool = Executors .newFixedThreadPool (20 );
57
64
}
58
65
59
66
public void sendEventsWithRetry (List <Event > events ) {
@@ -98,6 +105,14 @@ public void setFlushTimeout(long timeout) {
98
105
flushTimeout = timeout ;
99
106
}
100
107
108
+ public void setSendThreadPool (ExecutorService sendThreadPool ) {
109
+ this .sendThreadPool = sendThreadPool ;
110
+ }
111
+
112
+ public void setRetryThreadPool (ExecutorService retryThreadPool ) {
113
+ this .retryThreadPool = retryThreadPool ;
114
+ }
115
+
101
116
public void setCallbacks (AmplitudeCallbacks callbacks ) {
102
117
this .callbacks = callbacks ;
103
118
}
@@ -118,7 +133,7 @@ private CompletableFuture<Response> sendEvents(List<Event> events) {
118
133
throw new CompletionException (e );
119
134
}
120
135
return response ;
121
- });
136
+ }, supplyAsyncPool );
122
137
}
123
138
124
139
// Call this function if event not in current Retry list.
0 commit comments