kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 47ca100df76f6e5fc515aa44d0f878d2e6b9be8f308928f82879d9cff6464646 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-03-18 20:18 +01:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-03-18 20:18 +01:00 |
| Parents | 6091a1724bd4, 1805c994c4a9 |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +12 −6
| @@ -1081,12 +1081,12 @@ | ||
| 1081 | 1081 | return "cluster" + CLUSTER_ID.incrementAndGet(); |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | - private static ListeningExecutorService makeExecutor(int threads, String name) { | |
| 1084 | + private static ListeningExecutorService makeExecutor(int threads, String name, LinkedBlockingQueue<Runnable> workQueue) { | |
| 1085 | 1085 | ThreadPoolExecutor executor = new ThreadPoolExecutor(threads, |
| 1086 | 1086 | threads, |
| 1087 | 1087 | DEFAULT_THREAD_KEEP_ALIVE, |
| 1088 | 1088 | TimeUnit.SECONDS, |
| 1089 | - new LinkedBlockingQueue<Runnable>(), | |
| 1089 | + workQueue, | |
| 1090 | 1090 | threadFactory(name)); |
| 1091 | 1091 | |
| 1092 | 1092 | executor.allowCoreThreadTimeOut(true); |
| @@ -1119,17 +1119,23 @@ | ||
| 1119 | 1119 | |
| 1120 | 1120 | final ConvictionPolicy.Factory convictionPolicyFactory = new ConvictionPolicy.Simple.Factory(); |
| 1121 | 1121 | |
| 1122 | - final ScheduledExecutorService reconnectionExecutor = Executors.newScheduledThreadPool(2, threadFactory("Reconnection-%d")); | |
| 1122 | + final ScheduledThreadPoolExecutor reconnectionExecutor = new ScheduledThreadPoolExecutor(2, threadFactory("Reconnection-%d")); | |
| 1123 | 1123 | // scheduledTasksExecutor is used to process C* notifications. So having it mono-threaded ensures notifications are |
| 1124 | 1124 | // applied in the order received. |
| 1125 | - final ScheduledExecutorService scheduledTasksExecutor = Executors.newScheduledThreadPool(1, threadFactory("Scheduled Tasks-%d")); | |
| 1125 | + final ScheduledThreadPoolExecutor scheduledTasksExecutor = new ScheduledThreadPoolExecutor(1, threadFactory("Scheduled Tasks-%d")); | |
| 1126 | 1126 | |
| 1127 | 1127 | // Executor used for tasks that shouldn't be executed on an IO thread. Used for short-lived, generally non-blocking tasks |
| 1128 | 1128 | final ListeningExecutorService executor; |
| 1129 | 1129 | |
| 1130 | + // Work Queue used by executor. | |
| 1131 | + final LinkedBlockingQueue<Runnable> executorQueue = new LinkedBlockingQueue<Runnable>(); | |
| 1132 | + | |
| 1130 | 1133 | // An executor for tasks that might block some time, like creating new connection, but are generally not too critical. |
| 1131 | 1134 | final ListeningExecutorService blockingExecutor; |
| 1132 | 1135 | |
| 1136 | + // Work Queue used by blockingExecutor. | |
| 1137 | + final LinkedBlockingQueue<Runnable> blockingExecutorQueue = new LinkedBlockingQueue<Runnable>(); | |
| 1138 | + | |
| 1133 | 1139 | final ConnectionReaper reaper; |
| 1134 | 1140 | |
| 1135 | 1141 | final AtomicReference<CloseFuture> closeFuture = new AtomicReference<CloseFuture>(); |
| @@ -1150,8 +1156,8 @@ | ||
| 1150 | 1156 | this.configuration = configuration; |
| 1151 | 1157 | this.configuration.register(this); |
| 1152 | 1158 | |
| 1153 | - this.executor = makeExecutor(NON_BLOCKING_EXECUTOR_SIZE, "Cassandra Java Driver worker-%d"); | |
| 1154 | - this.blockingExecutor = makeExecutor(2, "Cassandra Java Driver blocking tasks worker-%d"); | |
| 1159 | + this.executor = makeExecutor(NON_BLOCKING_EXECUTOR_SIZE, "Cassandra Java Driver worker-%d", executorQueue); | |
| 1160 | + this.blockingExecutor = makeExecutor(2, "Cassandra Java Driver blocking tasks worker-%d", blockingExecutorQueue); | |
| 1155 | 1161 | |
| 1156 | 1162 | this.reaper = new ConnectionReaper(); |
| 1157 | 1163 |
modified driver-core/src/main/java/com/datastax/driver/core/Metrics.java +58 −0
| @@ -70,6 +70,34 @@ | ||
| 70 | 70 | } |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | + private final Gauge<Integer> executorQueueDepth = registry.register("executor-queue-depth", new Gauge<Integer>() { | |
| 74 | + @Override | |
| 75 | + public Integer getValue() { | |
| 76 | + return manager.executorQueue.size(); | |
| 77 | + } | |
| 78 | + }); | |
| 79 | + | |
| 80 | + private final Gauge<Integer> blockingExecutorQueueDepth = registry.register("blocking-executor-queue-depth", new Gauge<Integer>() { | |
| 81 | + @Override | |
| 82 | + public Integer getValue() { | |
| 83 | + return manager.blockingExecutorQueue.size(); | |
| 84 | + } | |
| 85 | + }); | |
| 86 | + | |
| 87 | + private final Gauge<Integer> reconnectionSchedulerQueueSize= registry.register("reconnection-scheduler-task-count", new Gauge<Integer>() { | |
| 88 | + @Override | |
| 89 | + public Integer getValue() { | |
| 90 | + return manager.reconnectionExecutor.getQueue().size(); | |
| 91 | + } | |
| 92 | + }); | |
| 93 | + | |
| 94 | + private final Gauge<Integer> taskSchedulerQueueSize = registry.register("task-scheduler-task-count", new Gauge<Integer>() { | |
| 95 | + @Override | |
| 96 | + public Integer getValue() { | |
| 97 | + return manager.scheduledTasksExecutor.getQueue().size(); | |
| 98 | + } | |
| 99 | + }); | |
| 100 | + | |
| 73 | 101 | Metrics(Cluster.Manager manager) { |
| 74 | 102 | this.manager = manager; |
| 75 | 103 | if (manager.configuration.getMetricsOptions().isJMXReportingEnabled()) { |
| @@ -177,6 +205,36 @@ | ||
| 177 | 205 | return openConnections; |
| 178 | 206 | } |
| 179 | 207 | |
| 208 | + /** | |
| 209 | + * @return The number of queued up tasks in the non-blocking executor (Cassandra Java Driver workers). | |
| 210 | + */ | |
| 211 | + public Gauge<Integer> getExecutorQueueDepth() { | |
| 212 | + return executorQueueDepth; | |
| 213 | + } | |
| 214 | + | |
| 215 | + /** | |
| 216 | + * @return The number of queued up tasks in the blocking executor (Cassandra Java Driver blocking tasks worker). | |
| 217 | + */ | |
| 218 | + public Gauge<Integer> getBlockingExecutorQueueDepth() { | |
| 219 | + return blockingExecutorQueueDepth; | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** | |
| 223 | + * @return The size of the work queue for the reconnection scheduler (Reconnection). A queue size > 0 does not | |
| 224 | + * necessarily indicate a backlog as some tasks may not have been scheduled to execute yet. | |
| 225 | + */ | |
| 226 | + public Gauge<Integer> getReconnectionSchedulerQueueSize() { | |
| 227 | + return reconnectionSchedulerQueueSize; | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 231 | + * @return The size of the work queue for the task scheduler (Scheduled Tasks). A queue size > 0 does not | |
| 232 | + * necessarily indicate a backlog as some tasks may not have been scheduled to execute yet. | |
| 233 | + */ | |
| 234 | + public Gauge<Integer> getTaskSchedulerQueueSize() { | |
| 235 | + return taskSchedulerQueueSize; | |
| 236 | + } | |
| 237 | + | |
| 180 | 238 | void shutdown() { |
| 181 | 239 | if (jmxReporter != null) |
| 182 | 240 | jmxReporter.stop(); |