From d35f3976080fdea85c9aba234d1cd69586473bb4 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 9 Feb 2011 19:01:05 +0200 Subject: [PATCH] remove timer service --- .../health/TransportClusterHealthAction.java | 8 +- .../client/transport/TransportClient.java | 4 - .../monitor/network/NetworkService.java | 8 +- .../elasticsearch/monitor/os/OsService.java | 8 +- .../monitor/process/ProcessService.java | 8 +- .../node/internal/InternalNode.java | 5 - .../elasticsearch/search/SearchService.java | 11 +- .../org/elasticsearch/timer/TimerModule.java | 32 ----- .../org/elasticsearch/timer/TimerService.java | 126 ------------------ .../zen/ping/unicast/UnicastZenPingTests.java | 2 - .../netty/benchmark/BenchmarkNettyClient.java | 2 - .../BenchmarkNettyLargeMessages.java | 2 - 12 files changed, 12 insertions(+), 204 deletions(-) delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index c57eda04094..fac28415870 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -35,7 +35,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportService; /** @@ -45,13 +44,10 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc private final ClusterName clusterName; - private final TimerService timerService; - @Inject public TransportClusterHealthAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - TimerService timerService, ClusterName clusterName) { + ClusterName clusterName) { super(settings, transportService, clusterService, threadPool); this.clusterName = clusterName; - this.timerService = timerService; } @Override protected String transportAction() { @@ -161,7 +157,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc if (waitForCounter == waitFor) { return response; } - if (timerService.estimatedTimeInMillis() > endTime) { + if (System.currentTimeMillis() > endTime) { response.timedOut = true; return response; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 0a82ce342e3..6cb03bdc85f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -63,8 +63,6 @@ import org.elasticsearch.node.internal.InternalSettingsPerparer; import org.elasticsearch.search.TransportSearchModule; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPoolModule; -import org.elasticsearch.timer.TimerModule; -import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; @@ -154,7 +152,6 @@ public class TransportClient extends AbstractClient { modules.add(new SettingsModule(settings)); modules.add(new NetworkModule()); modules.add(new ClusterNameModule(settings)); - modules.add(new TimerModule()); modules.add(new ThreadPoolModule(settings)); modules.add(new TransportSearchModule()); modules.add(new TransportModule(settings)); @@ -220,7 +217,6 @@ public class TransportClient extends AbstractClient { // ignore, might not be bounded } - injector.getInstance(TimerService.class).close(); injector.getInstance(ThreadPool.class).shutdown(); try { injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java index eda92d0d47e..28491e52bf6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.timer.TimerService; import java.net.InetAddress; import java.net.NetworkInterface; @@ -34,8 +33,6 @@ import java.util.Enumeration; */ public class NetworkService extends AbstractComponent { - private final TimerService timerService; - private final NetworkProbe probe; private final NetworkInfo info; @@ -44,10 +41,9 @@ public class NetworkService extends AbstractComponent { private NetworkStats cachedStats; - @Inject public NetworkService(Settings settings, NetworkProbe probe, TimerService timerService) { + @Inject public NetworkService(Settings settings, NetworkProbe probe) { super(settings); this.probe = probe; - this.timerService = timerService; this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); @@ -93,7 +89,7 @@ public class NetworkService extends AbstractComponent { } public synchronized NetworkStats stats() { - if ((timerService.estimatedTimeInMillis() - cachedStats.timestamp()) > refreshInterval.millis()) { + if ((System.currentTimeMillis() - cachedStats.timestamp()) > refreshInterval.millis()) { cachedStats = probe.networkStats(); } return cachedStats; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java index affeb64ab8f..20cbf1414d5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java @@ -23,15 +23,12 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.timer.TimerService; /** * @author kimchy (shay.banon) */ public class OsService extends AbstractComponent { - private final TimerService timerService; - private final OsProbe probe; private final OsInfo info; @@ -40,10 +37,9 @@ public class OsService extends AbstractComponent { private OsStats cachedStats; - @Inject public OsService(Settings settings, OsProbe probe, TimerService timerService) { + @Inject public OsService(Settings settings, OsProbe probe) { super(settings); this.probe = probe; - this.timerService = timerService; this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); @@ -59,7 +55,7 @@ public class OsService extends AbstractComponent { } public synchronized OsStats stats() { - if ((timerService.estimatedTimeInMillis() - cachedStats.timestamp()) > refreshInterval.millis()) { + if ((System.currentTimeMillis() - cachedStats.timestamp()) > refreshInterval.millis()) { cachedStats = probe.osStats(); } return cachedStats; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java index 48a09787aa9..d85e5d73fa7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java @@ -23,15 +23,12 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.timer.TimerService; /** * @author kimchy (shay.banon) */ public class ProcessService extends AbstractComponent { - private final TimerService timerService; - private final ProcessProbe probe; private final ProcessInfo info; @@ -40,9 +37,8 @@ public class ProcessService extends AbstractComponent { private ProcessStats cachedStats; - @Inject public ProcessService(Settings settings, ProcessProbe probe, TimerService timerService) { + @Inject public ProcessService(Settings settings, ProcessProbe probe) { super(settings); - this.timerService = timerService; this.probe = probe; this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); @@ -59,7 +55,7 @@ public class ProcessService extends AbstractComponent { } public synchronized ProcessStats stats() { - if ((timerService.estimatedTimeInMillis() - cachedStats.timestamp()) > refreshInterval.millis()) { + if ((System.currentTimeMillis() - cachedStats.timestamp()) > refreshInterval.millis()) { cachedStats = probe.processStats(); } return cachedStats; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java index 679538fc116..794a606a0ed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -75,8 +75,6 @@ import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.SearchService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPoolModule; -import org.elasticsearch.timer.TimerModule; -import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; @@ -127,7 +125,6 @@ public final class InternalNode implements Node { modules.add(new NodeEnvironmentModule()); modules.add(new ClusterNameModule(settings)); modules.add(new ThreadPoolModule(settings)); - modules.add(new TimerModule()); modules.add(new DiscoveryModule(settings)); modules.add(new ClusterModule(settings)); modules.add(new RestModule(settings)); @@ -286,8 +283,6 @@ public final class InternalNode implements Node { stopWatch.stop().start("script"); injector.getInstance(ScriptService.class).close(); - stopWatch.stop().start("timer"); - injector.getInstance(TimerService.class).close(); stopWatch.stop().start("thread_pool"); injector.getInstance(ThreadPool.class).shutdown(); try { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java index 6502496176c..6db84a2d031 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java @@ -50,7 +50,6 @@ import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.query.*; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.timer.TimerService; import java.io.IOException; import java.util.HashMap; @@ -69,8 +68,6 @@ public class SearchService extends AbstractLifecycleComponent { private final IndicesService indicesService; - private final TimerService timerService; - private final ScriptService scriptService; private final DfsPhase dfsPhase; @@ -93,12 +90,11 @@ public class SearchService extends AbstractLifecycleComponent { private final ImmutableMap elementParsers; - @Inject public SearchService(Settings settings, ClusterService clusterService, IndicesService indicesService, IndicesLifecycle indicesLifecycle, ThreadPool threadPool, TimerService timerService, + @Inject public SearchService(Settings settings, ClusterService clusterService, IndicesService indicesService, IndicesLifecycle indicesLifecycle, ThreadPool threadPool, ScriptService scriptService, DfsPhase dfsPhase, QueryPhase queryPhase, FetchPhase fetchPhase) { super(settings); this.clusterService = clusterService; this.indicesService = indicesService; - this.timerService = timerService; this.scriptService = scriptService; this.dfsPhase = dfsPhase; this.queryPhase = queryPhase; @@ -381,7 +377,7 @@ public class SearchService extends AbstractLifecycleComponent { } private void contextProcessedSuccessfully(SearchContext context) { - context.accessed(timerService.estimatedTimeInMillis()); + context.accessed(System.currentTimeMillis()); } private void cleanContext(SearchContext context) { @@ -471,11 +467,12 @@ public class SearchService extends AbstractLifecycleComponent { class Reaper implements Runnable { @Override public void run() { + long time = System.currentTimeMillis(); for (SearchContext context : activeContexts.values()) { if (context.lastAccessTime() == -1) { // its being processed or timeout is disabled continue; } - if ((timerService.estimatedTimeInMillis() - context.lastAccessTime() > context.keepAlive())) { + if ((time - context.lastAccessTime() > context.keepAlive())) { freeContext(context); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java deleted file mode 100644 index 774c8430de1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.timer; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - * @author kimchy (Shay Banon) - */ -public class TimerModule extends AbstractModule { - - @Override protected void configure() { - bind(TimerService.class).asEagerSingleton(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java deleted file mode 100644 index 74e0deb7c47..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.timer; - -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.timer.HashedWheelTimer; -import org.elasticsearch.common.timer.Timeout; -import org.elasticsearch.common.timer.Timer; -import org.elasticsearch.common.timer.TimerTask; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.threadpool.ThreadPool; - -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.common.unit.TimeValue.*; -import static org.elasticsearch.common.util.concurrent.EsExecutors.*; - -/** - * @author kimchy (Shay Banon) - */ -public class TimerService extends AbstractComponent { - - public static enum ExecutionType { - DEFAULT, - THREADED - } - - private final ThreadPool threadPool; - - private final Timer timer; - - private final TimeValue tickDuration; - - private final int ticksPerWheel; - - public TimerService(ThreadPool threadPool) { - this(ImmutableSettings.Builder.EMPTY_SETTINGS, threadPool); - } - - @Inject public TimerService(Settings settings, ThreadPool threadPool) { - super(settings); - this.threadPool = threadPool; - - this.tickDuration = componentSettings.getAsTime("tick_duration", timeValueMillis(100)); - this.ticksPerWheel = componentSettings.getAsInt("ticks_per_wheel", 1024); - - this.timer = new HashedWheelTimer(logger, daemonThreadFactory(settings, "timer"), tickDuration.millis(), TimeUnit.MILLISECONDS, ticksPerWheel); - } - - public void close() { - timer.stop(); - } - - public long estimatedTimeInMillis() { - // don't use the scheduled estimator so we won't wake up a thread each time - return System.currentTimeMillis(); - } - - public Timeout newTimeout(TimerTask task, TimeValue delay, ExecutionType executionType) { - return newTimeout(task, delay.nanos(), TimeUnit.NANOSECONDS, executionType); - } - - public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit, ExecutionType executionType) { - if (executionType == ExecutionType.THREADED) { - task = new ThreadedTimerTask(threadPool, task); - } - return timer.newTimeout(task, delay, unit); - } - - private class ThreadedTimerTask implements TimerTask { - - private final ThreadPool threadPool; - - private final TimerTask task; - - private ThreadedTimerTask(ThreadPool threadPool, TimerTask task) { - this.threadPool = threadPool; - this.task = task; - } - - @Override public void run(final Timeout timeout) throws Exception { - threadPool.cached().execute(new Runnable() { - @Override public void run() { - try { - task.run(timeout); - } catch (Exception e) { - logger.warn("An exception was thrown by " + TimerTask.class.getSimpleName() + ".", e); - } - } - }); - } - } - - private static class TimeEstimator implements Runnable { - - private long time = System.currentTimeMillis(); - - @Override public void run() { - this.time = System.currentTimeMillis(); - } - - public long time() { - return this.time; - } - } -} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java index 2d9cfa6ae20..acc715f2de8 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java @@ -30,7 +30,6 @@ import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.cached.CachedThreadPool; -import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; import org.testng.annotations.Test; @@ -45,7 +44,6 @@ public class UnicastZenPingTests { @Test public void testSimplePings() { ThreadPool threadPool = new CachedThreadPool(); - TimerService timerService = new TimerService(threadPool); ClusterName clusterName = new ClusterName("test"); NettyTransport transportA = new NettyTransport(threadPool); final TransportService transportServiceA = new TransportService(transportA, threadPool).start(); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java index 8fd582e1673..ff803d94c28 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.cached.CachedThreadPool; -import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.BaseTransportResponseHandler; import org.elasticsearch.transport.TransportException; import org.elasticsearch.transport.TransportService; @@ -59,7 +58,6 @@ public class BenchmarkNettyClient { final ThreadPool threadPool = new CachedThreadPool(settings); // final ThreadPool threadPool = new ScalingThreadPool(settings); - final TimerService timerService = new TimerService(settings, threadPool); final TransportService transportService = new TransportService(new NettyTransport(settings, threadPool), threadPool).start(); final DiscoveryNode node = new DiscoveryNode("server", new InetSocketTransportAddress("localhost", 9999)); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyLargeMessages.java b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyLargeMessages.java index 7ca48c62737..abe900bf4d1 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyLargeMessages.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyLargeMessages.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.cached.CachedThreadPool; -import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.*; import org.elasticsearch.transport.netty.NettyTransport; @@ -51,7 +50,6 @@ public class BenchmarkNettyLargeMessages { .build(); final ThreadPool threadPool = new CachedThreadPool(settings); - final TimerService timerService = new TimerService(settings, threadPool); final TransportService transportServiceServer = new TransportService(new NettyTransport(settings, threadPool), threadPool).start(); final TransportService transportServiceClient = new TransportService(new NettyTransport(settings, threadPool), threadPool).start();