-
Notifications
You must be signed in to change notification settings - Fork 616
HDDS-10573. [hsync] Add a freon tool to benchmark hsync/write concurrency #6925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
eb84870
4e48367
9a3fdae
440477a
1d273df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.ozone.freon; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.DatanodeRatisServerConfig; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.ratis.conf.RatisClientConfig; | ||
| import org.apache.hadoop.ozone.MiniOzoneCluster; | ||
| import org.apache.hadoop.ozone.client.ObjectStore; | ||
| import org.apache.hadoop.ozone.client.OzoneClient; | ||
| import org.apache.hadoop.ozone.client.OzoneVolume; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import picocli.CommandLine; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Duration; | ||
|
|
||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED; | ||
| import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OFS_URI_SCHEME; | ||
| import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| /** | ||
| * Tests Freon, with MiniOzoneCluster and validate data. | ||
| */ | ||
| public class TestHsyncGenerator { | ||
| private static MiniOzoneCluster cluster = null; | ||
|
|
||
| private static void startCluster(OzoneConfiguration conf) throws Exception { | ||
| DatanodeRatisServerConfig ratisServerConfig = | ||
| conf.getObject(DatanodeRatisServerConfig.class); | ||
| ratisServerConfig.setRequestTimeOut(Duration.ofSeconds(3)); | ||
| ratisServerConfig.setWatchTimeOut(Duration.ofSeconds(10)); | ||
| conf.setFromObject(ratisServerConfig); | ||
|
|
||
| RatisClientConfig.RaftConfig raftClientConfig = | ||
| conf.getObject(RatisClientConfig.RaftConfig.class); | ||
| raftClientConfig.setRpcRequestTimeout(Duration.ofSeconds(3)); | ||
| raftClientConfig.setRpcWatchRequestTimeout(Duration.ofSeconds(10)); | ||
| conf.setFromObject(raftClientConfig); | ||
| conf.set(OZONE_FS_HSYNC_ENABLED, "true"); | ||
|
|
||
| cluster = MiniOzoneCluster.newBuilder(conf) | ||
| .setNumDatanodes(5).build(); | ||
| cluster.waitForClusterToBeReady(); | ||
| } | ||
|
|
||
| static void shutdownCluster() { | ||
| if (cluster != null) { | ||
| cluster.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| @BeforeAll | ||
| public static void init() throws Exception { | ||
| OzoneConfiguration conf = new OzoneConfiguration(); | ||
| startCluster(conf); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void shutdown() { | ||
| shutdownCluster(); | ||
| } | ||
|
|
||
| @Test | ||
| public void test() throws IOException { | ||
| HsyncGenerator randomKeyGenerator = | ||
| new HsyncGenerator(cluster.getConf()); | ||
| CommandLine cmd = new CommandLine(randomKeyGenerator); | ||
|
|
||
| String volumeName = "vol1"; | ||
| String bucketName = "bucket1"; | ||
| try (OzoneClient client = cluster.newClient()) { | ||
| ObjectStore store = client.getObjectStore(); | ||
| store.createVolume(volumeName); | ||
| OzoneVolume volume = store.getVolume(volumeName); | ||
| volume.createBucket(bucketName); | ||
|
|
||
| //String rootPath = "o3fs://" + bucketName + "." + volumeName; | ||
| String rootPath = String.format("%s://%s/%s/%s/", | ||
| OZONE_OFS_URI_SCHEME, cluster.getConf().get(OZONE_OM_ADDRESS_KEY), | ||
| volumeName, bucketName); | ||
|
|
||
| // open 10 files to write (-n) | ||
| // 5 parallel writer threads (-t) | ||
| // each writer is associated with a thread pool of 5 syncers (--syncer-per-writer) | ||
| // each writer writes 1kb into the file (--bytes-per-write) | ||
| // each file is 1MB (--file-length) | ||
| int exitCode = cmd.execute( | ||
| "--path", rootPath, | ||
| "--bytes-per-write", "1024", | ||
| "--number-of-files", "2", | ||
| "-t", "5", | ||
| "-n", "100"); | ||
| assertEquals(0, exitCode); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.ozone.freon; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.hadoop.fs.FSDataOutputStream; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
|
|
||
| import com.codahale.metrics.Timer; | ||
| import org.apache.hadoop.ozone.util.PayloadUtils; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import picocli.CommandLine; | ||
| import picocli.CommandLine.Command; | ||
| import picocli.CommandLine.Option; | ||
|
|
||
| /** | ||
| * Data generator tool test hsync/write synchronization performance. | ||
| * | ||
| * Example usage: | ||
| * | ||
| * To generate hsync load with 10 threads on a single file: | ||
| * ozone freon hsync-generator -t 10 --bytes-per-write=1024 | ||
| * | ||
| * To generate hsync load with 10 threads on 3 files simultaneously: | ||
| * | ||
| * ozone freon hsync-generator -t 10 --bytes-per-write=1024 --number-of-files=3 | ||
| * | ||
| */ | ||
| @Command(name = "hg", | ||
| aliases = "hsync-generator", | ||
| description = "Generate writes and hsync traffic on one or multiple files.", | ||
| versionProvider = HddsVersionProvider.class, | ||
| mixinStandardHelpOptions = true, | ||
| showDefaultValues = true) | ||
| public class HsyncGenerator extends BaseFreonGenerator implements Callable<Void> { | ||
| private static final Logger LOG = LoggerFactory.getLogger(HsyncGenerator.class); | ||
|
|
||
| @CommandLine.ParentCommand | ||
| private Freon freon; | ||
|
|
||
| @Option(names = {"--path"}, | ||
| description = "Hadoop FS file system path. Use full path.", | ||
| defaultValue = "o3fs://bucket1.vol1") | ||
| private String rootPath; | ||
|
|
||
| @Option(names = {"--bytes-per-write"}, | ||
| description = "Size of each write", | ||
| defaultValue = "1024") | ||
| private int writeSize; | ||
|
|
||
| @Option(names = {"--number-of-files"}, | ||
| description = "Number of files to run test.", | ||
| defaultValue = "1") | ||
| private int numberOfFiles; | ||
|
|
||
| private Timer timer; | ||
|
|
||
| private OzoneConfiguration configuration; | ||
| private FileSystem fileSystem; | ||
| private FSDataOutputStream[] outputStreams; | ||
| private byte[] data; | ||
|
|
||
| public HsyncGenerator() { | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| HsyncGenerator(OzoneConfiguration ozoneConfiguration) { | ||
| this.configuration = ozoneConfiguration; | ||
| } | ||
|
|
||
| @Override | ||
| public Void call() throws Exception { | ||
| init(); | ||
|
|
||
| if (configuration == null) { | ||
| configuration = freon.createOzoneConfiguration(); | ||
| } | ||
| URI uri = URI.create(rootPath); | ||
| fileSystem = FileSystem.get(uri, configuration); | ||
|
jojochuang marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we should incorporate thread-local instance of Note: I'm currently working to unify freon tests using the FileSystem instance https://issues.apache.org/jira/browse/HDDS-11081, hopefully a patch will be raised soon.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ivandika3 We unlikely need more than one FileSystem in this tool. In #1479, the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway, I separated FileSystem per outputstream. |
||
|
|
||
| outputStreams = new FSDataOutputStream[numberOfFiles]; | ||
| for (int i = 0; i < numberOfFiles; i++) { | ||
| Path file = new Path(rootPath + "/" + generateObjectName(i)); | ||
| fileSystem.mkdirs(file.getParent()); | ||
| outputStreams[i] = fileSystem.create(file); | ||
| LOG.info("Created file for testing: {}", file); | ||
| } | ||
|
|
||
| timer = getMetrics().timer("hsync-generator"); | ||
| data = PayloadUtils.generatePayload(writeSize); | ||
|
|
||
| try { | ||
| runTests(this::sendHsync); | ||
| } finally { | ||
| for (FSDataOutputStream outputStream : outputStreams) { | ||
| outputStream.close(); | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private void sendHsync(long counter) throws Exception { | ||
| timer.time(() -> { | ||
| FSDataOutputStream outputStream = outputStreams[((int) counter) % numberOfFiles]; | ||
| outputStream.write(data); | ||
| outputStream.hsync(); | ||
| return null; | ||
| }); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.