Skip to content

Commit 1ec4dc3

Browse files
committed
Merge branch 'develop' of github.com:twitter/chill into Kryo3Upgrade
2 parents b234e46 + c37b59b commit 1ec4dc3

8 files changed

Lines changed: 42 additions & 7 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ jdk:
77
- openjdk6
88
- oraclejdk7
99
- oraclejdk8
10+
script: ./sbt ++$TRAVIS_SCALA_VERSION clean test doc
11+

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# chill #
22

3+
### 0.7.4 ###
4+
* If the inner Instantiator is cached we should just cache the kayo and…: https://github.com/twitter/chill/pull/243
5+
36
### 0.7.3 ###
47
* Update the build: https://github.com/twitter/chill/pull/248
58
* Use currentThread classloader: https://github.com/twitter/chill/pull/247

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Discussion occurs primarily on the [Chill mailing list](https://groups.google.co
159159

160160
## Maven
161161

162-
Chill modules are available on Maven Central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.7.3` and each scala project is published for `2.10` and `2.11`. Search [search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cchill) when in doubt.
162+
Chill modules are available on Maven Central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.7.4` and each scala project is published for `2.10` and `2.11`. Search [search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cchill) when in doubt.
163163

164164
## Authors
165165

chill-hadoop/src/main/java/com/twitter/chill/hadoop/KryoSerialization.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,24 @@
3737
public class KryoSerialization extends Configured implements Serialization<Object> {
3838
// can't be final because we need to set them in setConf (for Configured)
3939
KryoPool kryoPool;
40-
Kryo testKryo;
40+
41+
private static KryoPool cachedPool = null;
42+
private static KryoInstantiator cachedKryoInst = null;
43+
44+
/**
45+
* Hadoop will re-initialize the KryoSerialization on every spill
46+
* This gets very expensive if you output a lot from a mapper to initialize the chill/kryo stack
47+
* The KryoInstantiator's already do some caching, and figuring out if its safe to cache,
48+
* so here we piggy back on that to avoid generating new kryo's or kryo pools
49+
*/
50+
public static synchronized void resetOrUpdateFromCache(KryoSerialization instance, KryoInstantiator kryoInst){
51+
if(kryoInst != cachedKryoInst) {
52+
cachedPool = KryoPool.withByteArrayOutputStream(MAX_CACHED_KRYO, kryoInst);
53+
cachedKryoInst = kryoInst;
54+
}
55+
instance.kryoPool = cachedPool;
56+
}
57+
4158
/**
4259
* Since each thread only needs 1 Kryo, the pool doesn't need more
4360
* space than the number of threads. We guess that there are 4 hyperthreads /
@@ -69,8 +86,7 @@ public void setConf(Configuration conf) {
6986
if (conf != null) {
7087
try {
7188
KryoInstantiator kryoInst = new ConfiguredInstantiator(new HadoopConfig(conf));
72-
testKryo = kryoInst.newKryo();
73-
kryoPool = KryoPool.withByteArrayOutputStream(MAX_CACHED_KRYO, kryoInst);
89+
resetOrUpdateFromCache(this, kryoInst);
7490
}
7591
catch(ConfigurationException cx) {
7692
// This interface can't throw
@@ -86,7 +102,7 @@ public void setConf(Configuration conf) {
86102
*/
87103
public boolean accept(Class<?> aClass) {
88104
try {
89-
return (testKryo.getRegistration(aClass) != null);
105+
return kryoPool.hasRegistration(aClass);
90106
} catch (IllegalArgumentException e) {
91107
return false;
92108
}

chill-java/src/main/java/com/twitter/chill/KryoPool.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,14 @@ public byte[] toBytesWithoutClass(Object obj) {
131131
release(serde);
132132
}
133133
}
134+
135+
public boolean hasRegistration(Class obj) {
136+
SerDeState serde = borrow();
137+
try {
138+
return serde.hasRegistration(obj);
139+
}
140+
finally {
141+
release(serde);
142+
}
143+
}
134144
}

chill-java/src/main/java/com/twitter/chill/SerDeState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@ public Object readClassAndObject() {
6868
public void writeOutputTo(OutputStream os) throws IOException {
6969
os.write(outputToBytes());
7070
}
71+
72+
public boolean hasRegistration(Class obj) {
73+
return kryo.getRegistration(obj) != null;
74+
}
7175
}

chill-java/src/main/java/com/twitter/chill/config/ConfiguredInstantiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ConfiguredInstantiator extends KryoInstantiator {
4040
protected final KryoInstantiator delegate;
4141

4242
/** Key we use to configure this class.
43-
* Format: &lt;class of KryoInstantiator&gt;(:&lt;base64 serialized instantiator&gt;)
43+
* Format: {@literal<class of KryoInstantiator>(:<base64 serialized instantiator>)}
4444
* if there is no serialized instantiator, we use the reflected instance
4545
* as the delegate
4646
*/

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "0.8.0-SNAPSHOT"
1+
version in ThisBuild := "0.8.0-SNAPSHOT"

0 commit comments

Comments
 (0)