Commit eb47eb3c4f41feb42bc95c186404c8e2dae80cbe
1 parent
8fd37663
Fixed concurrency issues on high load
Showing
3 changed files
with
7 additions
and
3 deletions
... | ... | @@ -29,6 +29,7 @@ import org.thingsboard.server.kafka.*; |
29 | 29 | import javax.annotation.PostConstruct; |
30 | 30 | import javax.annotation.PreDestroy; |
31 | 31 | import java.util.concurrent.ExecutorService; |
32 | +import java.util.concurrent.LinkedBlockingQueue; | |
32 | 33 | import java.util.concurrent.SynchronousQueue; |
33 | 34 | import java.util.concurrent.ThreadPoolExecutor; |
34 | 35 | import java.util.concurrent.TimeUnit; |
... | ... | @@ -67,7 +68,7 @@ public class RemoteTransportApiService { |
67 | 68 | |
68 | 69 | @PostConstruct |
69 | 70 | public void init() { |
70 | - this.transportCallbackExecutor = new ThreadPoolExecutor(0, 100, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); | |
71 | + this.transportCallbackExecutor = new ThreadPoolExecutor(0, 100, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); | |
71 | 72 | |
72 | 73 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TransportApiResponseMsg> responseBuilder = TBKafkaProducerTemplate.builder(); |
73 | 74 | responseBuilder.settings(kafkaSettings); | ... | ... |
... | ... | @@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap; |
32 | 32 | import java.util.concurrent.ConcurrentMap; |
33 | 33 | import java.util.concurrent.ExecutorService; |
34 | 34 | import java.util.concurrent.Executors; |
35 | +import java.util.concurrent.LinkedBlockingQueue; | |
35 | 36 | import java.util.concurrent.ScheduledExecutorService; |
36 | 37 | import java.util.concurrent.SynchronousQueue; |
37 | 38 | import java.util.concurrent.ThreadPoolExecutor; |
... | ... | @@ -277,7 +278,7 @@ public abstract class AbstractTransportService implements TransportService { |
277 | 278 | new TbRateLimits(perDevicesLimitsConf); |
278 | 279 | } |
279 | 280 | this.schedulerExecutor = Executors.newSingleThreadScheduledExecutor(); |
280 | - this.transportCallbackExecutor = new ThreadPoolExecutor(0, 20, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); | |
281 | + this.transportCallbackExecutor = new ThreadPoolExecutor(0, 20, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); | |
281 | 282 | this.schedulerExecutor.scheduleAtFixedRate(this::checkInactivityAndReportActivity, sessionReportTimeout, sessionReportTimeout, TimeUnit.MILLISECONDS); |
282 | 283 | } |
283 | 284 | ... | ... |
... | ... | @@ -31,7 +31,9 @@ import java.util.concurrent.ConcurrentMap; |
31 | 31 | import java.util.concurrent.ExecutorService; |
32 | 32 | import java.util.concurrent.Executors; |
33 | 33 | import java.util.concurrent.LinkedBlockingDeque; |
34 | +import java.util.concurrent.LinkedBlockingQueue; | |
34 | 35 | import java.util.concurrent.ScheduledExecutorService; |
36 | +import java.util.concurrent.ThreadPoolExecutor; | |
35 | 37 | import java.util.concurrent.TimeUnit; |
36 | 38 | import java.util.concurrent.TimeoutException; |
37 | 39 | import java.util.concurrent.atomic.AtomicInteger; |
... | ... | @@ -70,7 +72,7 @@ public abstract class AbstractBufferedRateExecutor<T extends AsyncTask, F extend |
70 | 72 | this.concurrencyLimit = concurrencyLimit; |
71 | 73 | this.queue = new LinkedBlockingDeque<>(queueLimit); |
72 | 74 | this.dispatcherExecutor = Executors.newFixedThreadPool(dispatcherThreads); |
73 | - this.callbackExecutor = Executors.newFixedThreadPool(callbackThreads); | |
75 | + this.callbackExecutor = new ThreadPoolExecutor(callbackThreads, 50, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); | |
74 | 76 | this.timeoutExecutor = Executors.newSingleThreadScheduledExecutor(); |
75 | 77 | this.perTenantLimitsEnabled = perTenantLimitsEnabled; |
76 | 78 | this.perTenantLimitsConfiguration = perTenantLimitsConfiguration; | ... | ... |