Original article: http://fusesource.com/docs/broker/5.4/tuning/GenTuning-Protocols.html#GenTuning-Protocols-Compress
Overview: Protocol optimization can be performed on different protocol layers, as shown below:
- TCP transport.
- OpenWire protocol.
- Enabling compression.
TCP transport (TCP transmission): Generally, increasing the Buffer size of the TCP layer can improve the performance of the TCP layer.
- Socket buffer size-The default TCP Socket buffer size is 64 KB. This design is only suitable for the original TCP protocol. This size is the most suitable for the original modern network. The following experience can be used to estimate the appropriate TCP socket buffer size.
Buffer size = BandWidth (BandWidth) X Round-Trip-Time (Round-Trip latency)
Round-Trip-Time indicates the length of Time (Ping Time) for sending a packet from TCP to receiving the packet ), A typical practice is to double the Socket buffer size to 128 K.
Example:
tcp://hostA:61617?socketBufferSize=131072
For more information, see Wikipedia's article Network Improvement.
- I/O buffer size-I/O buffer is used to cache data between TCP and its upper-layer protocol (like OpenWire. The default I/O buffer size is 8 K. You can double this size to achieve better performance. Example:
tcp://hostA:61617?ioBufferSize=16384
OpenWire protocol: OpenWire protocol provides several options to adjust performance, as shown in Table 1.1.
Table 1.1. OpenWire Parameters Affecting Performance
Parameter |
Default |
Description |
cacheEnabled |
true |
Specifies whether to cache commonly repeated values, in order to optimize into aling. |
cacheSize |
1024 |
The number of values to cache. Increase this value to improve performance of stored aling. |
tcpNoDelayEnabled |
false |
Whentrue , Disable the Nagles algorithm. the Nagles algorithm was devised to avoid sending tiny TCP packets containing only one or two bytes of data; for example, when TCP is used with the Telnet protocol. if you disable the Nagles algorithm, packets can be sent more promptly, but there is a risk that the number of very small packets will increase. |
tightEncodingEnabled |
true |
Whentrue , Implement a more compact encoding of basic data types. this results in smaller messages and better network performance, but comes at a cost of more calculation and demans made on CPU time. A trade off is therefore required: you need to determine whether the network or the CPU is the main factor that limits performance. |
To set any item, you must add it to the URI.wireFormat
Prefix, for example, doubling the OperWire cache, you can specify the cache size in the URI, as shown below
tcp://hostA:61617?wireFormat.cacheSize=2048
Enabling compression: if the application sends large messages and you know that the network is very slow, you should consider compressing the data transmitted over the network. When compression is allowed, all message bodies (excluding message headers) in JMS are compressed before transmission. This will generate small messages and improve network performance. But what's worse is that it increases the CPU pressure.
For compression, you need to setActiveMQConnectionFactory
OfuseCompression
. For example, if you set compression when the Client initializes the JMS Connection, you need to insert the following code.
// Java
...
// Create the connection.
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory (user, password, url );
ConnectionFactory. setUseCompression (true );
Connection connection = connectionFactory. createConnection ();
Connection. start ();
In addition, you can setjms.useCompression
To compress, as shown below:
tcp://hostA:61617?jms.useCompression=true