diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java index 507e164..13a581c 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java @@ -130,7 +130,8 @@ void waitNotify(TestDispatcher dispatcher) { dispatcher.notified = false; } - RMApp storeApp(RMStateStore store, ApplicationId appId, long submitTime, + protected RMApp storeApp(RMStateStore store, ApplicationId appId, + long submitTime, long startTime) throws Exception { ApplicationSubmissionContext context = new ApplicationSubmissionContextPBImpl(); @@ -146,7 +147,8 @@ RMApp storeApp(RMStateStore store, ApplicationId appId, long submitTime, return mockApp; } - ContainerId storeAttempt(RMStateStore store, ApplicationAttemptId attemptId, + protected ContainerId storeAttempt(RMStateStore store, + ApplicationAttemptId attemptId, String containerIdStr, Token appToken, SecretKey clientTokenMasterKey, TestDispatcher dispatcher) throws Exception { @@ -450,7 +452,7 @@ public void testRMDTSecretManagerStateStore( } - private Token generateAMRMToken( + protected Token generateAMRMToken( ApplicationAttemptId attemptId, AMRMTokenSecretManager appTokenMgr) { AMRMTokenIdentifier appTokenId = diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java new file mode 100644 index 0000000..5c6571f --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java @@ -0,0 +1,156 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.hadoop.yarn.server.resourcemanager.recovery; + +import java.util.ArrayList; +import javax.crypto.SecretKey; +import org.apache.hadoop.security.token.Token; +import org.apache.hadoop.util.Tool; +import org.apache.hadoop.util.ToolRunner; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.security.AMRMTokenIdentifier; +import org.apache.hadoop.yarn.server.resourcemanager.security + .AMRMTokenSecretManager; +import org.apache.hadoop.yarn.server.resourcemanager.security + .ClientToAMTokenSecretManagerInRM; +import org.apache.hadoop.yarn.util.ConverterUtils; +import org.junit.After; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.conf.HAUtil; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Before; +import org.junit.Test; + +public class TestZKRMStateStorePerf extends RMStateStoreTestBase implements Tool { + public static final Log LOG = LogFactory.getLog(TestZKRMStateStore.class); + + // Configurable variables for performance test + private int ZK_PERF_NUM_APP_DEFAULT = 100; + private int ZK_PERF_NUM_APPATTEMPT_PER_APP = 100; + + private static final int ZK_TIMEOUT_MS = 100000; + private final long clusterTimeStamp = 1352994193343L; + + private YarnConfiguration conf = new YarnConfiguration(); + private String workingZnode = "/Test"; + private ZKRMStateStore store; + private AMRMTokenSecretManager appTokenMgr; + private ClientToAMTokenSecretManagerInRM clientToAMTokenMgr; + + @Before + public void setUp() throws Exception { + super.setUp(); + conf = new YarnConfiguration(); + conf.set(YarnConfiguration.RM_ZK_ADDRESS, hostPort); + conf.set(YarnConfiguration.ZK_RM_STATE_STORE_PARENT_PATH, workingZnode); + store = new ZKRMStateStore(); + store.init(conf); + store.start(); + appTokenMgr = + new AMRMTokenSecretManager(conf); + clientToAMTokenMgr = + new ClientToAMTokenSecretManagerInRM(); + } + + @After + public void tearDown() throws Exception { + if (store != null) { + store.stop(); + } + super.tearDown(); + } + + @Override + public int run(String[] args) throws Exception { + int numApp = 1000; + int numAppAttemptPerApp = 100; + + long submitTime = System.currentTimeMillis(); + long startTime = System.currentTimeMillis() + 1234; + + ArrayList applicationIds = new ArrayList(); + ArrayList attemptIds = + new ArrayList(); + ArrayList containerIds = new ArrayList(); + TestDispatcher dispatcher = new TestDispatcher(); + store.setRMDispatcher(dispatcher); + + for (int i = 0; i < numApp; i++) { + ApplicationId appId = ApplicationId.newInstance(clusterTimeStamp, i); + applicationIds.add(appId); + for (int j = 0; j < numAppAttemptPerApp; j++) { + ApplicationAttemptId attemptId = + ApplicationAttemptId.newInstance(appId, j); + attemptIds.add(attemptId); + } + } + + for (ApplicationId appId : applicationIds) { + storeApp(store, appId, submitTime, startTime); + } + + for (ApplicationAttemptId attemptId : attemptIds) { + Token tokenId = + generateAMRMToken(attemptId, appTokenMgr); + SecretKey clientTokenKey = + clientToAMTokenMgr.createMasterKey(attemptId); + storeAttempt(store, attemptId, + ContainerId.newInstance(attemptId, 0).toString(), + tokenId, clientTokenKey, dispatcher); + } + + long storeStart = System.currentTimeMillis(); + store.loadState(); + long storeEnd = System.currentTimeMillis(); + + long loadTime = storeEnd - storeStart; + + String resultMsg = "ZKRMStateStore takes " + loadTime + " msec to loadState."; + LOG.info(resultMsg); + System.out.println(resultMsg); + + return 0; + } + + @Override + public void setConf(Configuration conf) { + this.conf = new YarnConfiguration(conf); + } + + @Override + public Configuration getConf() { + return conf; + } + + @Test + public void perfZKRMStateStore() throws Exception { + run(new String[1]); + } + + static public void main(String[] args) throws Exception { + TestZKRMStateStorePerf perf = new TestZKRMStateStorePerf(); + ToolRunner.run(perf, args); + System.exit(0); + } +}