Skip to content

Instantly share code, notes, and snippets.

@kofemann
Last active August 29, 2022 12:54
Show Gist options
  • Save kofemann/7e7c1502b080118e78332715c6f8004c to your computer and use it in GitHub Desktop.
Save kofemann/7e7c1502b080118e78332715c6f8004c to your computer and use it in GitHub Desktop.
Simple chimera file freate rate benchmark
package org.dcache.chimera.posix;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.UUID.randomUUID;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import java.util.UUID;
import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
import liquibase.resource.ClassLoaderResourceAccessor;
import org.dcache.chimera.ChimeraFsException;
import org.dcache.chimera.FileSystemProvider;
import org.dcache.chimera.FsInode;
import org.dcache.chimera.JdbcFs;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
public class CreateBenchmark {
protected FileSystemProvider _fs;
protected FsInode _rootInode;
protected HikariDataSource _dataSource;
@Setup
public void setUp() throws IOException, SQLException, LiquibaseException {
Properties dbProperties = new Properties();
dbProperties.load(new FileReader("chimera-test.properties", UTF_8));
HikariConfig config = new HikariConfig();
config.setJdbcUrl(dbProperties.getProperty("chimera.db.url"));
config.setUsername(dbProperties.getProperty("chimera.db.user"));
config.setPassword(dbProperties.getProperty("chimera.db.password"));
config.setMaximumPoolSize(Runtime.getRuntime().availableProcessors()*2);
config.setMinimumIdle(100);
_dataSource = new HikariDataSource(config);
try (Connection conn = _dataSource.getConnection()) {
conn.createStatement().execute("DROP SCHEMA public CASCADE;");
conn.createStatement().execute("CREATE SCHEMA public;");
conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn));
Liquibase liquibase = new Liquibase("org/dcache/chimera/changelog/changelog-master.xml",
new ClassLoaderResourceAccessor(), database);
liquibase.update("");
}
PlatformTransactionManager txManager = new DataSourceTransactionManager(_dataSource);
_fs = new JdbcFs(_dataSource, txManager);
_rootInode = _fs.path2inode("/");
}
@Benchmark
@Threads(value = 8)
public FsInode benchmarkCreate() throws ChimeraFsException {
return _rootInode.create(randomUUID().toString(), 0, 0, 644);
}
@TearDown
public void tearDown() throws Exception {
_dataSource.close();
_fs.close();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(CreateBenchmark.class.getSimpleName())
.build();
new Runner(opt).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment