ARTEMIS-1616 OpenWire improvements

Avoided copy of CoreMessage when not needed and cached lambda on hot path
This commit is contained in:
Francesco Nigro 2018-01-16 14:24:32 +01:00 committed by Clebert Suconic
parent 04a9884d30
commit 2db4eafc4d
1 changed files with 19 additions and 14 deletions

View File

@ -85,6 +85,8 @@ public class AMQSession implements SessionCallback {
private final OpenWireProtocolManager protocolManager; private final OpenWireProtocolManager protocolManager;
private final Runnable enableAutoReadAndTtl;
private final CoreMessageObjectPools coreMessageObjectPools = new CoreMessageObjectPools(); private final CoreMessageObjectPools coreMessageObjectPools = new CoreMessageObjectPools();
public AMQSession(ConnectionInfo connInfo, public AMQSession(ConnectionInfo connInfo,
@ -102,6 +104,7 @@ public class AMQSession implements SessionCallback {
OpenWireFormat marshaller = (OpenWireFormat) connection.getMarshaller(); OpenWireFormat marshaller = (OpenWireFormat) connection.getMarshaller();
this.converter = new OpenWireMessageConverter(marshaller.copy()); this.converter = new OpenWireMessageConverter(marshaller.copy());
this.enableAutoReadAndTtl = this::enableAutoReadAndTtl;
} }
public boolean isClosed() { public boolean isClosed() {
@ -325,7 +328,7 @@ public class AMQSession implements SessionCallback {
boolean sendProducerAck) throws Exception { boolean sendProducerAck) throws Exception {
messageSend.setBrokerInTime(System.currentTimeMillis()); messageSend.setBrokerInTime(System.currentTimeMillis());
ActiveMQDestination destination = messageSend.getDestination(); final ActiveMQDestination destination = messageSend.getDestination();
ActiveMQDestination[] actualDestinations = null; ActiveMQDestination[] actualDestinations = null;
if (destination.isComposite()) { if (destination.isComposite()) {
@ -335,7 +338,7 @@ public class AMQSession implements SessionCallback {
actualDestinations = new ActiveMQDestination[]{destination}; actualDestinations = new ActiveMQDestination[]{destination};
} }
org.apache.activemq.artemis.api.core.Message originalCoreMsg = getConverter().inbound(messageSend, coreMessageObjectPools); final org.apache.activemq.artemis.api.core.Message originalCoreMsg = getConverter().inbound(messageSend, coreMessageObjectPools);
originalCoreMsg.putStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString(), this.connection.getState().getInfo().getClientId()); originalCoreMsg.putStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString(), this.connection.getState().getInfo().getClientId());
@ -356,14 +359,15 @@ public class AMQSession implements SessionCallback {
connection.getContext().setDontSendReponse(true); connection.getContext().setDontSendReponse(true);
} }
for (int i = 0; i < actualDestinations.length; i++) { for (int i = 0, actualDestinationsCount = actualDestinations.length; i < actualDestinationsCount; i++) {
ActiveMQDestination dest = actualDestinations[i]; final ActiveMQDestination dest = actualDestinations[i];
SimpleString address = SimpleString.toSimpleString(dest.getPhysicalName(), coreMessageObjectPools.getAddressStringSimpleStringPool()); final SimpleString address = SimpleString.toSimpleString(dest.getPhysicalName(), coreMessageObjectPools.getAddressStringSimpleStringPool());
org.apache.activemq.artemis.api.core.Message coreMsg = originalCoreMsg.copy(); //the last coreMsg could be directly the original one -> it avoid 1 copy if actualDestinations > 1 and ANY copy if actualDestinations == 1
final org.apache.activemq.artemis.api.core.Message coreMsg = (i == actualDestinationsCount - 1) ? originalCoreMsg : originalCoreMsg.copy();
coreMsg.setAddress(address); coreMsg.setAddress(address);
if (actualDestinations[i].isQueue()) { if (dest.isQueue()) {
checkAutoCreateQueue(SimpleString.toSimpleString(actualDestinations[i].getPhysicalName(), coreMessageObjectPools.getAddressStringSimpleStringPool()), actualDestinations[i].isTemporary()); checkAutoCreateQueue(address, dest.isTemporary());
coreMsg.setRoutingType(RoutingType.ANYCAST); coreMsg.setRoutingType(RoutingType.ANYCAST);
} else { } else {
coreMsg.setRoutingType(RoutingType.MULTICAST); coreMsg.setRoutingType(RoutingType.MULTICAST);
@ -424,12 +428,8 @@ public class AMQSession implements SessionCallback {
//non-persistent messages goes here, by default we stop reading from //non-persistent messages goes here, by default we stop reading from
//transport //transport
connection.getTransportConnection().setAutoRead(false); connection.getTransportConnection().setAutoRead(false);
if (!store.checkMemory(() -> { if (!store.checkMemory(enableAutoReadAndTtl)) {
connection.getTransportConnection().setAutoRead(true); enableAutoReadAndTtl();
connection.enableTtl();
})) {
connection.getTransportConnection().setAutoRead(true);
connection.enableTtl();
throw new ResourceAllocationException("Queue is full " + address); throw new ResourceAllocationException("Queue is full " + address);
} }
@ -448,6 +448,11 @@ public class AMQSession implements SessionCallback {
} }
} }
private void enableAutoReadAndTtl() {
connection.getTransportConnection().setAutoRead(true);
connection.enableTtl();
}
public String convertWildcard(String physicalName) { public String convertWildcard(String physicalName) {
return OPENWIRE_WILDCARD.convert(physicalName, server.getConfiguration().getWildcardConfiguration()); return OPENWIRE_WILDCARD.convert(physicalName, server.getConfiguration().getWildcardConfiguration());
} }