Permalink
Browse files

Make Kryo buffer size configurable, with reasonable defaults

  • Loading branch information...
1 parent 91ff183 commit be285416364777531034950794ed545eb223d1ac Bruce Robbins committed Mar 4, 2011
Showing with 23 additions and 4 deletions.
  1. +13 −2 src/main/java/io/s4/serialize/KryoSerDeser.java
  2. +10 −2 src/main/resources/s4_core_conf_typical.xml
@@ -24,6 +24,17 @@
public class KryoSerDeser implements SerializerDeserializer {
private Kryo kryo = new Kryo();
+
+ private int initialBufferSize = 2048;
+ private int maxBufferSize = 256*1024;
+
+ public void setInitialBufferSize(int initialBufferSize) {
+ this.initialBufferSize = initialBufferSize;
+ }
+
+ public void setMaxBufferSize(int maxBufferSize) {
+ this.maxBufferSize = maxBufferSize;
+ }
public KryoSerDeser() {
kryo.setRegistrationOptional(true);
@@ -48,13 +59,13 @@ public void write(ByteBuffer buf, java.util.UUID uuid) {
@Override
public Object deserialize(byte[] rawMessage) {
- ObjectBuffer buffer = new ObjectBuffer(kryo);
+ ObjectBuffer buffer = new ObjectBuffer(kryo, initialBufferSize, maxBufferSize);
return buffer.readClassAndObject(rawMessage);
}
@Override
public byte[] serialize(Object message) {
- ObjectBuffer buffer = new ObjectBuffer(kryo);
+ ObjectBuffer buffer = new ObjectBuffer(kryo, initialBufferSize, maxBufferSize);
return buffer.writeClassAndObject(message);
}
}
@@ -4,6 +4,12 @@
<property name="location">
<value>classpath:s4_core.properties</value>
</property>
+ <property name="properties">
+ <props>
+ <prop key="kryoSerDeser.initialBufferSize">2048</prop>
+ <prop key="kryoSerDeser.maxBufferSize">262144</prop>
+ </props>
+ </property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
@@ -22,8 +28,10 @@
<property name="monitor" ref="monitor"/>
</bean>
- <bean id="serDeser" class="io.s4.serialize.KryoSerDeser"/>
-
+ <bean id="serDeser" class="io.s4.serialize.KryoSerDeser">
+ <property name="initialBufferSize" value="${kryoSerDeser.initialBufferSize}"/>
+ <property name="maxBufferSize" value="${kryoSerDeser.maxBufferSize}"/>
+ </bean>
<!--START: Dispatchers for control event processor.

0 comments on commit be28541

Please sign in to comment.