|
29 | 29 | import io.fabric8.kubernetes.api.model.Quantity; |
30 | 30 | import io.fabric8.kubernetes.api.model.ResourceRequirements; |
31 | 31 | import io.fabric8.kubernetes.api.model.Toleration; |
| 32 | +import io.reactivex.schedulers.Schedulers; |
32 | 33 | import io.reactivex.subjects.PublishSubject; |
33 | 34 | import org.jooq.DSLContext; |
34 | 35 | import org.jooq.Insert; |
@@ -80,19 +81,23 @@ private enum Operators { |
80 | 81 |
|
81 | 82 | PodEventsToDatabase(final IConnectionPool dbConnectionPool) { |
82 | 83 | this.dbConnectionPool = dbConnectionPool; |
83 | | - eventStream.buffer(BATCH_INTERVAL_IN_MS, TimeUnit.MILLISECONDS, BATCH_COUNT).subscribe(podEvents -> { |
84 | | - if (podEvents.isEmpty()) { |
85 | | - return; |
86 | | - } |
87 | | - final List<Query> queries = new ArrayList<>(); |
88 | | - for (final BatchedTask task: podEvents) { |
89 | | - queries.addAll(task.queries()); |
90 | | - } |
91 | | - LOG.info("Inserting {} queries from a batch of {} events", queries.size(), podEvents.size()); |
92 | | - dbConnectionPool.getConnectionToDb().batch(queries).execute(); |
93 | | - for (final BatchedTask task: podEvents) { |
94 | | - task.future().set(true); |
95 | | - } |
| 84 | + eventStream.subscribeOn(Schedulers.single()) |
| 85 | + .buffer(BATCH_INTERVAL_IN_MS, TimeUnit.MILLISECONDS, BATCH_COUNT) |
| 86 | + .subscribe(podEvents -> { |
| 87 | + if (podEvents.isEmpty()) { |
| 88 | + return; |
| 89 | + } |
| 90 | + final List<Query> queries = new ArrayList<>(); |
| 91 | + for (final BatchedTask task: podEvents) { |
| 92 | + queries.addAll(task.queries()); |
| 93 | + } |
| 94 | + final long now = System.nanoTime(); |
| 95 | + dbConnectionPool.getConnectionToDb().batch(queries).execute(); |
| 96 | + LOG.info("Inserted {} queries from a batch of {} events in time {}", queries.size(), podEvents.size(), |
| 97 | + System.nanoTime() - now); |
| 98 | + for (final BatchedTask task: podEvents) { |
| 99 | + task.future().set(true); |
| 100 | + } |
96 | 101 | }); |
97 | 102 | } |
98 | 103 |
|
|
0 commit comments