use of io.aeron.driver.MinMulticastFlowControlSupplier in project Aeron by real-logic.
the class MinFlowControlSystemTest method shouldRemoveDeadTaggedReceiverWithMinMulticastFlowControlStrategy.
@Test
@InterruptAfter(10)
void shouldRemoveDeadTaggedReceiverWithMinMulticastFlowControlStrategy() {
final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
int numMessagesLeftToSend = numMessagesToSend;
int numFragmentsReadFromA = 0, numFragmentsReadFromB = 0;
driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
driverAContext.multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
launch();
subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
while (!subscriptionA.isConnected() || !subscriptionB.isConnected() || !publication.isConnected()) {
Tests.yield();
}
boolean isBClosed = false;
while (numFragmentsReadFromA < numMessagesToSend) {
if (numMessagesLeftToSend > 0) {
if (publication.offer(buffer, 0, buffer.capacity()) >= 0L) {
numMessagesLeftToSend--;
}
}
// A keeps up
numFragmentsReadFromA += subscriptionA.poll(fragmentHandlerA, 10);
// B receives up to 1/8 of the messages, then stops
if (numFragmentsReadFromB < (numMessagesToSend / 8)) {
numFragmentsReadFromB += subscriptionB.poll(fragmentHandlerB, 10);
} else if (!isBClosed) {
subscriptionB.close();
isBClosed = true;
}
}
verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
use of io.aeron.driver.MinMulticastFlowControlSupplier in project aeron by real-logic.
the class ClusterConfig method create.
/**
* Create a new ClusterConfig. This call allows for 2 separate lists of hostnames, so that there can be 'external'
* addresses for ingress requests and 'internal' addresses that will handle all the cluster replication and
* control traffic.
*
* @param nodeId id for this node.
* @param ingressHostnames list of hostnames that will receive ingress request traffic.
* @param clusterHostnames list of hostnames that will receive cluster traffic.
* @param portBase base port to derive remaining ports from.
* @param clusteredService instance of the clustered service that will run with this configuration.
* @param additionalServices instances of additional clustered services that will run with this configuration.
* @return configuration that wraps all aeron service configuration.
*/
public static ClusterConfig create(final int nodeId, final List<String> ingressHostnames, final List<String> clusterHostnames, final int portBase, final ClusteredService clusteredService, final ClusteredService... additionalServices) {
if (nodeId >= ingressHostnames.size()) {
throw new IllegalArgumentException("nodeId=" + nodeId + " >= ingressHostnames.size()=" + ingressHostnames.size());
}
final String clusterMembers = clusterMembers(ingressHostnames, clusterHostnames, portBase);
final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
final File baseDir = new File(System.getProperty("user.dir"), "aeron-cluster-" + nodeId);
final String hostname = clusterHostnames.get(nodeId);
final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, ARCHIVE_SUB_DIR)).controlChannel(udpChannel(nodeId, hostname, portBase, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlRequestStreamId(archiveContext.localControlStreamId()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().clusterMemberId(nodeId).clusterMembers(clusterMembers).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).archiveContext(aeronArchiveContext.clone()).serviceCount(1 + additionalServices.length).replicationChannel("aeron:udp?endpoint=" + hostname + ":0");
final List<ClusteredServiceContainer.Context> serviceContexts = new ArrayList<>();
final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(clusteredService).serviceId(0);
serviceContexts.add(clusteredServiceContext);
for (int i = 0; i < additionalServices.length; i++) {
final ClusteredServiceContainer.Context additionalServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(additionalServices[i]).serviceId(i + 1);
serviceContexts.add(additionalServiceContext);
}
return new ClusterConfig(mediaDriverContext, archiveContext, aeronArchiveContext, consensusModuleContext, serviceContexts);
}
use of io.aeron.driver.MinMulticastFlowControlSupplier in project aeron by real-logic.
the class ClusterTest method before.
@Before
public void before() {
final String aeronDirName = CommonContext.getAeronDirectoryName();
for (int i = 0; i < MEMBER_COUNT; i++) {
echoServices[i] = new EchoService(latch);
final String baseDirName = aeronDirName + "-" + i;
final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(memberSpecificPort(ARCHIVE_CONTROL_REQUEST_CHANNEL, i)).controlRequestStreamId(100 + i).controlResponseChannel(memberSpecificPort(ARCHIVE_CONTROL_RESPONSE_CHANNEL, i)).controlResponseStreamId(110 + i).aeronDirectoryName(baseDirName);
drivers[i] = ClusteredMediaDriver.launch(new MediaDriver.Context().aeronDirectoryName(baseDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).errorHandler(Throwable::printStackTrace).dirDeleteOnStart(true), new Archive.Context().maxCatalogEntries(MAX_CATALOG_ENTRIES).aeronDirectoryName(baseDirName).archiveDir(new File(baseDirName, "archive")).controlChannel(archiveCtx.controlRequestChannel()).controlStreamId(archiveCtx.controlRequestStreamId()).localControlChannel("aeron:ipc?term-length=64k").localControlStreamId(archiveCtx.controlRequestStreamId()).threadingMode(ArchiveThreadingMode.SHARED).deleteArchiveOnStart(true), new ConsensusModule.Context().clusterMemberId(i).clusterMembers(CLUSTER_MEMBERS).appointedLeaderId(0).aeronDirectoryName(baseDirName).clusterDir(new File(baseDirName, "consensus-module")).ingressChannel("aeron:udp?term-length=64k").logChannel(memberSpecificPort(LOG_CHANNEL, i)).archiveContext(archiveCtx.clone()).deleteDirOnStart(true));
containers[i] = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().aeronDirectoryName(baseDirName).archiveContext(archiveCtx.clone()).clusteredServiceDir(new File(baseDirName, "service")).clusteredService(echoServices[i]).errorHandler(Throwable::printStackTrace).deleteDirOnStart(true));
}
client = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(aeronDirName + "-0").ingressChannel("aeron:udp").clusterMemberEndpoints("localhost:20110", "localhost:20111", "localhost:20112").lock(new NoOpLock()));
}
use of io.aeron.driver.MinMulticastFlowControlSupplier in project Aeron by real-logic.
the class BasicAuctionClusteredServiceNode method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
// <1>
final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
",");
final String hostname = hostnames[nodeId];
// <3>
final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
// <4>
final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
// end::main[]
// tag::media_driver[]
final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).terminationHook(barrier::signal).errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
// end::media_driver[]
final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
// tag::archive[]
final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
// end::archive[]
// tag::archive_client[]
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
// end::archive_client[]
// tag::consensus_module[]
final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
nodeId).clusterMembers(// <2>
clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
new File(baseDir, "cluster")).ingressChannel(// <4>
"aeron:udp?term-length=64k").logChannel(// <5>
logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
logReplicationChannel(hostname)).archiveContext(// <7>
aeronArchiveContext.clone());
// end::consensus_module[]
// tag::clustered_service[]
final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
aeronDirName).archiveContext(// <2>
aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
// tag::running[]
try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
consensusModuleContext);
ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
clusteredServiceContext)) {
System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
// <3>
barrier.await();
System.out.println("[" + nodeId + "] Exiting");
}
// end::running[]
}
use of io.aeron.driver.MinMulticastFlowControlSupplier in project Aeron by real-logic.
the class ClusterConfig method create.
/**
* Create a new ClusterConfig. This call allows for 2 separate lists of hostnames, so that there can be 'external'
* addresses for ingress requests and 'internal' addresses that will handle all the cluster replication and
* control traffic.
*
* @param nodeId id for this node.
* @param ingressHostnames list of hostnames that will receive ingress request traffic.
* @param clusterHostnames list of hostnames that will receive cluster traffic.
* @param portBase base port to derive remaining ports from.
* @param clusteredService instance of the clustered service that will run with this configuration.
* @param additionalServices instances of additional clustered services that will run with this configuration.
* @return configuration that wraps all aeron service configuration.
*/
public static ClusterConfig create(final int nodeId, final List<String> ingressHostnames, final List<String> clusterHostnames, final int portBase, final ClusteredService clusteredService, final ClusteredService... additionalServices) {
if (nodeId >= ingressHostnames.size()) {
throw new IllegalArgumentException("nodeId=" + nodeId + " >= ingressHostnames.size()=" + ingressHostnames.size());
}
final String clusterMembers = clusterMembers(ingressHostnames, clusterHostnames, portBase);
final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
final File baseDir = new File(System.getProperty("user.dir"), "aeron-cluster-" + nodeId);
final String hostname = clusterHostnames.get(nodeId);
final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, ARCHIVE_SUB_DIR)).controlChannel(udpChannel(nodeId, hostname, portBase, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlRequestStreamId(archiveContext.localControlStreamId()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().clusterMemberId(nodeId).clusterMembers(clusterMembers).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).archiveContext(aeronArchiveContext.clone()).serviceCount(1 + additionalServices.length).replicationChannel("aeron:udp?endpoint=" + hostname + ":0");
final List<ClusteredServiceContainer.Context> serviceContexts = new ArrayList<>();
final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(clusteredService).serviceId(0);
serviceContexts.add(clusteredServiceContext);
for (int i = 0; i < additionalServices.length; i++) {
final ClusteredServiceContainer.Context additionalServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(additionalServices[i]).serviceId(i + 1);
serviceContexts.add(additionalServiceContext);
}
return new ClusterConfig(mediaDriverContext, archiveContext, aeronArchiveContext, consensusModuleContext, serviceContexts);
}
Aggregations