Skip to content

Commit

Permalink
Tweak configurations in stress tests
Browse files Browse the repository at this point in the history
Small cleanups and sharing of code
  • Loading branch information
davidegrohmann committed Sep 16, 2016
1 parent 511086c commit ec1c53d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 30 deletions.
Expand Up @@ -33,8 +33,6 @@
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.function.IntFunction; import java.util.function.IntFunction;


import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.coreedge.core.CoreEdgeClusterSettings;
import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.discovery.HazelcastDiscoveryServiceFactory; import org.neo4j.coreedge.discovery.HazelcastDiscoveryServiceFactory;
import org.neo4j.helpers.AdvertisedSocketAddress; import org.neo4j.helpers.AdvertisedSocketAddress;
Expand All @@ -45,12 +43,13 @@
import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong; import static java.lang.Long.parseLong;
import static java.lang.System.getProperty; import static java.lang.System.getProperty;
import static java.util.Collections.emptyMap;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.neo4j.StressTestingHelper.ensureExistsAndEmpty; import static org.neo4j.StressTestingHelper.ensureExistsAndEmpty;
import static org.neo4j.StressTestingHelper.fromEnv; import static org.neo4j.StressTestingHelper.fromEnv;
import static org.neo4j.coreedge.stresstests.ClusterConfiguration.configureBackup;
import static org.neo4j.coreedge.stresstests.ClusterConfiguration.configureRaftLogRotationAndPruning;
import static org.neo4j.coreedge.stresstests.ClusterConfiguration.configureTxLogRotationAndPruning;
import static org.neo4j.function.Suppliers.untilTimeExpired; import static org.neo4j.function.Suppliers.untilTimeExpired;
import static org.neo4j.kernel.configuration.Settings.TRUE;


public class BackupStoreCopyInteractionStressTesting public class BackupStoreCopyInteractionStressTesting
{ {
Expand Down Expand Up @@ -83,18 +82,19 @@ public void shouldBehaveCorrectlyUnderStress() throws Exception
BiFunction<Boolean,Integer,SocketAddress> backupAddress = ( isCore, id ) -> BiFunction<Boolean,Integer,SocketAddress> backupAddress = ( isCore, id ) ->
new AdvertisedSocketAddress( "localhost", (isCore ? baseCoreBackupPort : baseEdgeBackupPort) + id ); new AdvertisedSocketAddress( "localhost", (isCore ? baseCoreBackupPort : baseEdgeBackupPort) + id );


Map<String,String> coreParams = new HashMap<>(); Map<String,String> coreParams =
coreParams.put( CoreEdgeClusterSettings.raft_log_rotation_size.name(), "1K" ); configureRaftLogRotationAndPruning( configureTxLogRotationAndPruning( new HashMap<>() ) );
coreParams.put( CoreEdgeClusterSettings.raft_log_pruning_frequency.name(), "1s" ); Map<String,String> edgeParams = configureTxLogRotationAndPruning( new HashMap<>() );
coreParams.put( CoreEdgeClusterSettings.raft_log_pruning_strategy.name(), "keep_none" );


Map<String,IntFunction<String>> paramsPerCoreInstance = configureBackup( (id) -> backupAddress.apply( true, id ) ); Map<String,IntFunction<String>> instanceCoreParams =
Map<String,IntFunction<String>> paramsPerEdgeInstance = configureBackup( (id) -> backupAddress.apply( false, id ) ); configureBackup( new HashMap<>(), id -> backupAddress.apply( true, id ) );
Map<String,IntFunction<String>> instanceEdgeParams =
configureBackup( new HashMap<>(), id -> backupAddress.apply( false, id ) );


HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory(); HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
Cluster cluster = Cluster cluster =
new Cluster( clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, new Cluster( clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams,
paramsPerCoreInstance, emptyMap(), paramsPerEdgeInstance, StandardV3_0.NAME ); instanceCoreParams, edgeParams, instanceEdgeParams, StandardV3_0.NAME );


AtomicBoolean stopTheWorld = new AtomicBoolean(); AtomicBoolean stopTheWorld = new AtomicBoolean();
BooleanSupplier keepGoing = BooleanSupplier keepGoing =
Expand Down Expand Up @@ -123,12 +123,4 @@ public void shouldBehaveCorrectlyUnderStress() throws Exception
FileUtils.deleteRecursively( clusterDirectory ); FileUtils.deleteRecursively( clusterDirectory );
FileUtils.deleteRecursively( backupDirectory ); FileUtils.deleteRecursively( backupDirectory );
} }

private static Map<String,IntFunction<String>> configureBackup( IntFunction<SocketAddress> address )
{
Map<String,IntFunction<String>> settings = new HashMap<>();
settings.put( OnlineBackupSettings.online_backup_enabled.name(), id -> TRUE );
settings.put( OnlineBackupSettings.online_backup_server.name(), id -> address.apply( id ).toString() );
return settings;
}
} }
Expand Up @@ -22,7 +22,6 @@
import org.junit.Test; import org.junit.Test;


import java.io.File; import java.io.File;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
Expand All @@ -31,10 +30,7 @@
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.IntFunction;


import org.neo4j.coreedge.core.CoreEdgeClusterSettings;
import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.discovery.HazelcastDiscoveryServiceFactory; import org.neo4j.coreedge.discovery.HazelcastDiscoveryServiceFactory;
import org.neo4j.io.fs.FileUtils; import org.neo4j.io.fs.FileUtils;
Expand All @@ -47,6 +43,8 @@
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.neo4j.StressTestingHelper.ensureExistsAndEmpty; import static org.neo4j.StressTestingHelper.ensureExistsAndEmpty;
import static org.neo4j.StressTestingHelper.fromEnv; import static org.neo4j.StressTestingHelper.fromEnv;
import static org.neo4j.coreedge.stresstests.ClusterConfiguration.configureRaftLogRotationAndPruning;
import static org.neo4j.coreedge.stresstests.ClusterConfiguration.configureTxLogRotationAndPruning;
import static org.neo4j.function.Suppliers.untilTimeExpired; import static org.neo4j.function.Suppliers.untilTimeExpired;


public class CatchupStoreCopyInteractionStressTesting public class CatchupStoreCopyInteractionStressTesting
Expand All @@ -70,15 +68,14 @@ public void shouldBehaveCorrectlyUnderStress() throws Exception


File clusterDirectory = ensureExistsAndEmpty( new File( workingDirectory, "cluster" ) ); File clusterDirectory = ensureExistsAndEmpty( new File( workingDirectory, "cluster" ) );


Map<String,String> coreParams = new HashMap<>(); Map<String,String> coreParams =
coreParams.put( CoreEdgeClusterSettings.raft_log_rotation_size.name(), "1K" ); configureRaftLogRotationAndPruning( configureTxLogRotationAndPruning( new HashMap<>() ) );
coreParams.put( CoreEdgeClusterSettings.raft_log_pruning_frequency.name(), "1s" ); Map<String,String> edgeParams = configureTxLogRotationAndPruning( new HashMap<>() );
coreParams.put( CoreEdgeClusterSettings.raft_log_pruning_strategy.name(), "keep_none" );


HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory(); HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
Cluster cluster = Cluster cluster =
new Cluster( clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, new Cluster( clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams,
emptyMap(), emptyMap(), emptyMap(), StandardV3_0.NAME ); emptyMap(), edgeParams, emptyMap(), StandardV3_0.NAME );


AtomicBoolean stopTheWorld = new AtomicBoolean(); AtomicBoolean stopTheWorld = new AtomicBoolean();
BooleanSupplier keepGoing = BooleanSupplier keepGoing =
Expand Down
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.coreedge.stresstests;

import java.util.Map;
import java.util.function.IntFunction;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.coreedge.core.CoreEdgeClusterSettings;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.SocketAddress;
import org.neo4j.kernel.configuration.Settings;

import static org.neo4j.kernel.configuration.Settings.TRUE;

class ClusterConfiguration
{
static Map<String,String> configureRaftLogRotationAndPruning( Map<String,String> settings )
{
settings.put( CoreEdgeClusterSettings.raft_log_rotation_size.name(), "1K" );
settings.put( CoreEdgeClusterSettings.raft_log_pruning_frequency.name(), "250ms" );
settings.put( CoreEdgeClusterSettings.raft_log_pruning_strategy.name(), "keep_none" );
return settings;
}

static Map<String,String> configureTxLogRotationAndPruning( Map<String,String> settings )
{
settings.put( GraphDatabaseSettings.keep_logical_logs.name(), Settings.FALSE );
settings.put( GraphDatabaseSettings.logical_log_rotation_threshold.name(), "1M" );
return settings;
}

static Map<String,IntFunction<String>> configureBackup( Map<String,IntFunction<String>> settings,
IntFunction<SocketAddress> address )
{
settings.put( OnlineBackupSettings.online_backup_enabled.name(), id -> TRUE );
settings.put( OnlineBackupSettings.online_backup_server.name(), id -> address.apply( id ).toString() );
return settings;
}
}
Expand Up @@ -37,7 +37,7 @@ protected boolean doWorkOnMember( boolean isCore, int id )
{ {
ClusterMember member = isCore ? cluster.getCoreMemberById( id ) : cluster.getEdgeMemberById( id ); ClusterMember member = isCore ? cluster.getCoreMemberById( id ) : cluster.getEdgeMemberById( id );
member.shutdown(); member.shutdown();
LockSupport.parkNanos( 2_000_000_000 ); LockSupport.parkNanos( 5_000_000_000L );
member.start(); member.start();
return true; return true;
} }
Expand Down
Expand Up @@ -24,6 +24,7 @@


import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.graphdb.DatabaseShutdownException; import org.neo4j.graphdb.DatabaseShutdownException;
import org.neo4j.graphdb.Node;


class Workload extends RepeatUntilCallable class Workload extends RepeatUntilCallable
{ {
Expand All @@ -42,7 +43,15 @@ protected boolean doWork()
{ {
cluster.coreTx( ( db, tx ) -> cluster.coreTx( ( db, tx ) ->
{ {
db.createNode(); Node node = db.createNode();
node.setProperty( "prop1", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop2", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop3", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop4", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop5", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop6", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop7", "let's add some data here so the transaction logs rotate more often..." );
node.setProperty( "prop8", "let's add some data here so the transaction logs rotate more often..." );
tx.success(); tx.success();
} ); } );
} }
Expand Down

0 comments on commit ec1c53d

Please sign in to comment.