@Override public void start() throws Exception { if (started.compareAndSet(false, true)) { if (memoryUsage != null) { memoryUsage.start(); } if (systemUsage.getStoreUsage() != null) { systemUsage.getStoreUsage().start(); } if (systemUsage.getTempUsage() != null) { systemUsage.getTempUsage().start(); } systemUsage.getMemoryUsage().addUsageListener(this); messages.start(); if (getExpireMessagesPeriod() > 0) { scheduler.executePeriodically(expireMessagesTask, getExpireMessagesPeriod()); } doPageIn(false); } }
public SystemUsage getSystemUsage() { try { if (systemUsage == null) { systemUsage = new SystemUsage("Main", getPersistenceAdapter(), getTempDataStore(), getJobSchedulerStore()); systemUsage.setExecutor(getExecutor()); systemUsage.getMemoryUsage().setLimit(1024L * 1024 * 1024 * 1); // 1 GB systemUsage.getTempUsage().setLimit(1024L * 1024 * 1024 * 50); // 50 GB systemUsage.getStoreUsage().setLimit(1024L * 1024 * 1024 * 100); // 100 GB systemUsage.getJobSchedulerUsage().setLimit(1024L * 1024 * 1024 * 50); // 50 GB addService(this.systemUsage); } return systemUsage; } catch (IOException e) { LOG.error("Cannot create SystemUsage", e); throw new RuntimeException("Fatally failed to create SystemUsage" + e.getMessage(), e); } }
public void setSystemUsage(SystemUsage memoryManager) { if (this.systemUsage != null) { removeService(this.systemUsage); } this.systemUsage = memoryManager; if (this.systemUsage.getExecutor()==null) { this.systemUsage.setExecutor(getExecutor()); } addService(this.systemUsage); }
/** * @return the consumerUsageManager * @throws IOException */ public SystemUsage getConsumerSystemUsage() throws IOException { if (this.consumerSystemUsaage == null) { if (splitSystemUsageForProducersConsumers) { this.consumerSystemUsaage = new SystemUsage(getSystemUsage(), "Consumer"); float portion = consumerSystemUsagePortion / 100f; this.consumerSystemUsaage.getMemoryUsage().setUsagePortion(portion); addService(this.consumerSystemUsaage); } else { consumerSystemUsaage = getSystemUsage(); } } return this.consumerSystemUsaage; }
public void activate(SystemUsage memoryManager, ConnectionContext context, ConsumerInfo info, RegionBroker regionBroker) throws Exception { if (!active.get()) { this.context = context; this.info = info; this.active.set(true); this.offlineTimestamp.set(-1); dispatchPending(); this.usageManager.getMemoryUsage().addUsageListener(this);
protected final void waitForSpace(ConnectionContext context, ProducerBrokerExchange producerBrokerExchange, Usage<?> usage, int highWaterMark, String warning) throws IOException, InterruptedException, ResourceAllocationException { if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { if (isFlowControlLogRequired()) { getLog().info("sendFailIfNoSpace, forcing exception on send, usage: {}: {}", usage, warning); if (!context.isNetworkConnection() && systemUsage.getSendFailIfNoSpaceAfterTimeout() != 0) { if (!usage.waitForSpace(systemUsage.getSendFailIfNoSpaceAfterTimeout(), highWaterMark)) { if (isFlowControlLogRequired()) { getLog().info("sendFailIfNoSpaceAfterTimeout expired, forcing exception on send, usage: {}: {}", usage, warning); long start = System.currentTimeMillis(); producerBrokerExchange.blockingOnFlowControl(true); destinationStatistics.getBlockedSends().increment(); while (!usage.waitForSpace(1000, highWaterMark)) { if (context.getStopping().get()) { throw new IOException("Connection closed, send aborted.");
final boolean sendProducerAck = !message.isResponseRequired() && producerInfo.getWindowSize() > 0 && !context.isInRecoveryMode(); message.setRegionDestination(this); fastProducer(context, producerInfo); if (isProducerFlowControl() && context.isProducerFlowControl()) { getActiveMQDestination().getQualifiedName(), memoryUsage.getLimit()); } else { LOG.debug("{}, Usage Manager memory limit reached {}. Producers will be throttled to the rate at which messages are removed from this destination to prevent flooding it. See http://activemq.apache.org/producer-flow-control.html for more info.", getActiveMQDestination().getQualifiedName(), memoryUsage.getLimit()); if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { throw new javax.jms.ResourceAllocationException("Usage Manager memory limit (" + memoryUsage.getLimit() + ") reached. Rejecting send for producer (" + message.getProducerId() + ") to prevent flooding " + getActiveMQDestination().getQualifiedName() + "." + " See http://activemq.apache.org/producer-flow-control.html for more info"); if (context.getStopping().get()) { throw new IOException("Connection closed, send aborted."); if (message.isExpired()) { getDestinationStatistics().getExpired().increment(); LOG.debug("Expired message: {}", message); return;
ConnectionContext context = producerExchange.getConnectionContext(); final String jobId = (String) messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_ID); final Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_CRON); final Object periodValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD); final Object delayValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY); String physicalName = messageSend.getDestination().getPhysicalName(); boolean schedularManage = physicalName.regionMatches(true, 0, ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION, 0, ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION.length()); if (systemUsage.getJobSchedulerUsage() != null) { JobSchedulerUsage usage = systemUsage.getJobSchedulerUsage(); if (usage.isFull()) { final String logMessage = "Job Scheduler Store is Full (" + long nextWarn = start; while (!usage.waitForSpace(1000)) { if (context.getStopping().get()) { throw new IOException("Connection closed, send aborted."); if (context.isInTransaction()) { context.getTransaction().addSynchronization(new Synchronization() { @Override public void afterCommit() throws Exception {
getSubscriptionStatistics().getEnqueues().increment(); synchronized (matchedListMutex) { while (active) { while (matched.isFull()) { if (getContext().getStopping().get()) { LOG.warn("{}: stopped waiting for space in pendingMessage cursor for: {}", toString(), node.getMessageId()); getSubscriptionStatistics().getEnqueues().decrement(); return; toString(), matched, matched.getSystemUsage().getTempUsage().getPercentUsage(), matched.getSystemUsage().getMemoryUsage().getPercentUsage() }); warnedAboutWait = true;
public void deactivate(boolean keepDurableSubsActive, long lastDeliveredSequenceId) throws Exception { LOG.debug("Deactivating keepActive={}, {}", keepDurableSubsActive, this); active.set(false); this.keepDurableSubsActive = keepDurableSubsActive; offlineTimestamp.set(System.currentTimeMillis()); usageManager.getMemoryUsage().removeUsageListener(this); topicsToDeactivate.add(topic); } else { topic.getDestinationStatistics().getInflight().subtract(dispatched.size());
@Override public synchronized void start() throws Exception { if (!started.compareAndSet(false, true)) { return; wireFormat.setVersion(brokerService.getStoreOpenWireVersion()); this.usageManager.getMemoryUsage().addUsageListener(this); longTermPersistence.start(); createTransactionStore(); recover(); this.scheduler = new Scheduler("Journal Scheduler"); this.scheduler.start(); this.scheduler.executePeriodically(periodicCheckpointTask, checkpointInterval / 10);
@Override public void stop() throws Exception { this.usageManager.getMemoryUsage().removeUsageListener(this); if (!started.compareAndSet(true, false)) { return; } this.scheduler.cancel(periodicCheckpointTask); this.scheduler.stop(); // Take one final checkpoint and stop checkpoint processing. checkpoint(true, true); checkpointTask.shutdown(); ThreadPoolUtils.shutdown(checkpointExecutor); checkpointExecutor = null; queues.clear(); topics.clear(); IOException firstException = null; try { journal.close(); } catch (Exception e) { firstException = IOExceptionSupport.create("Failed to close journals: " + e, e); } longTermPersistence.stop(); if (firstException != null) { throw firstException; } }
@Override public void stop() throws Exception { if (started.compareAndSet(true, false)) { super.stop(); if (systemUsage != null) { systemUsage.getMemoryUsage().removeUsageListener(this); } } }
@Override public void start() throws Exception { if (started.compareAndSet(false, true)) { if( this.broker != null) { wireFormat.setVersion(this.broker.getBrokerService().getStoreOpenWireVersion()); } super.start(); if (systemUsage != null) { systemUsage.getMemoryUsage().addUsageListener(this); } } }
@Override public void stop() throws Exception { if (started.compareAndSet(true, false)) { if (taskRunner != null) { taskRunner.shutdown(); scheduler.cancel(expireMessagesTask); systemUsage.getMemoryUsage().removeUsageListener(this); if (memoryUsage != null) { memoryUsage.stop(); if (systemUsage.getStoreUsage() != null) { systemUsage.getStoreUsage().stop();
private void startActiveMqBroker() throws Exception { this.activeMQBroker = new BrokerService(); this.activeMQBroker.addConnector("stomp://localhost:" + this.port); this.activeMQBroker.setStartAsync(false); this.activeMQBroker.setPersistent(false); this.activeMQBroker.setUseJmx(false); this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.start(); }
ActiveMQDestination queryDestination = ActiveMQDestination.createDestination(destinationQuery,msgDest.getDestinationType()); Set<Destination> destinations = getDestinations(queryDestination); statsMessage.setLong("size", stats.getMessages().getCount()); statsMessage.setLong("enqueueCount", stats.getEnqueues().getCount()); statsMessage.setLong("dequeueCount", stats.getDequeues().getCount()); statsMessage.setJMSCorrelationID(messageSend.getCorrelationId()); sendStats(producerExchange.getConnectionContext(), statsMessage, replyTo); SystemUsage systemUsage = brokerService.getSystemUsage(); DestinationStatistics stats = regionBroker.getDestinationStatistics(); statsMessage.setString("brokerName", regionBroker.getBrokerName()); statsMessage.setInt("memoryPercentUsage", systemUsage.getMemoryUsage().getPercentUsage()); statsMessage.setLong("memoryUsage", systemUsage.getMemoryUsage().getUsage()); statsMessage.setLong("memoryLimit", systemUsage.getMemoryUsage().getLimit()); statsMessage.setInt("storePercentUsage", systemUsage.getStoreUsage().getPercentUsage()); statsMessage.setLong("storeUsage", systemUsage.getStoreUsage().getUsage()); statsMessage.setLong("storeLimit", systemUsage.getStoreUsage().getLimit()); statsMessage.setInt("tempPercentUsage", systemUsage.getTempUsage().getPercentUsage()); statsMessage.setLong("tempUsage", systemUsage.getTempUsage().getUsage()); statsMessage.setLong("tempLimit", systemUsage.getTempUsage().getLimit()); statsMessage.setDouble("averageEnqueueTime", stats.getProcessTime().getAverageTime()); statsMessage.setDouble("maxEnqueueTime", stats.getProcessTime().getMaxTime());
if (destination.isTemporary() || broker == null || store == null) { this.messages = new VMPendingMessageCursor(isPrioritizedMessages()); } else { this.systemUsage = brokerService.getSystemUsage(); memoryUsage.setParent(systemUsage.getMemoryUsage()); this.taskRunner = taskFactory.createTaskRunner(this, "Queue:" + destination.getPhysicalName()); } while (!listener.done()); } else { destinationStatistics.getMessages().add(messageCount);
message.setRegionDestination(this); ProducerState state = producerExchange.getProducerState(); if (state == null) { final boolean sendProducerAck = !message.isResponseRequired() && producerInfo.getWindowSize() > 0 && !context.isInRecoveryMode(); if (message.isExpired()) { ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize()); context.getConnection().dispatchAsync(ack); if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { ResourceAllocationException resourceAllocationException = sendMemAllocationException; if (resourceAllocationException == null) { if (resourceAllocationException == null) { sendMemAllocationException = resourceAllocationException = new ResourceAllocationException("Usage Manager Memory Limit reached on " + getActiveMQDestination().getQualifiedName() + "." + " See http://activemq.apache.org/producer-flow-control.html for more info"); getDestinationStatistics().getBlockedSends().increment(); producerExchange.blockingOnFlowControl(true); if (!context.isNetworkConnection() && systemUsage.getSendFailIfNoSpaceAfterTimeout() != 0) { flowControlTimeoutMessages.add(new TimeoutMessage(message, context, systemUsage .getSendFailIfNoSpaceAfterTimeout()));
@Override public void initialize() throws Exception { this.messages=new VMPendingMessageCursor(false); this.messages.setMemoryUsageHighWaterMark(getCursorMemoryHighWaterMark()); this.systemUsage = brokerService.getSystemUsage(); memoryUsage.setParent(systemUsage.getMemoryUsage()); this.taskRunner = taskFactory.createTaskRunner(this, "TempQueue: " + destination.getPhysicalName()); }