kryo

Serializing an arbitrary Java object with Kryo (getting IllegalAccessError)

不问归期 提交于 2019-12-01 18:28:29
Motivation: To aid in remote debugging (Java), it's useful to be able to request remote servers to send over arbitrary objects to my local machine for inspection. However, this means that the remote server must be able to serialize an arbitrary java object that is not known in advance at runtime. So I asked around and stumbled on the Kryo serialization library . From Kryo's documentation , a major feature is that it's very robust at serializing arbitrary java objects. Objects don't have to implement Serializable , don't need no-arg constructors to be deserializable and I don't even need to

Redis 序列化方式StringRedisSerializer、FastJsonRedisSerializer和KryoRedisSerializer

孤街浪徒 提交于 2019-11-30 06:22:35
当我们的数据存储到Redis的时候,我们的键(key)和值(value)都是通过Spring提供的Serializer序列化到数据库的。RedisTemplate默认使用的是JdkSerializationRedisSerializer,StringRedisTemplate默认使用的是StringRedisSerializer。 Spring Data JPA为我们提供了下面的Serializer:GenericToStringSerializer、Jackson2JsonRedisSerializer、JacksonJsonRedisSerializer、JdkSerializationRedisSerializer、OxmSerializer、StringRedisSerializer。 序列化方式对比: JdkSerializationRedisSerializer: 使用JDK提供的序列化功能。 优点是反序列化时不需要提供类型信息(class),但缺点是需要实现Serializable接口,还有序列化后的结果非常庞大,是JSON格式的5倍左右,这样就会消耗redis服务器的大量内存。 Jackson2JsonRedisSerializer: 使用Jackson库将对象序列化为JSON字符串。优点是速度快,序列化后的字符串短小精悍,不需要实现Serializable接口

Kryo serialization refuses to register class

好久不见. 提交于 2019-11-29 10:24:32
I'm trying to use kryo serialization with: kryo.setRegistrationRequired(true); I keep getting the following error saying that a certain class is not registered: java.lang.IllegalArgumentException: Class is not registered: com.my.package.MyClass[] Note: To register this class use: kryo.register(com.my.package.MyClass[].class); However, I do register it: kryo.register(classOf[MyClass[_]]) When I set Log.TRACE() I get the following output: 00:11 TRACE: [kryo] Register class ID 51: com.my.package.MyClass (com.esotericsoftware.kryo.serializers.FieldSerializer) Why does it say it is not registered,

Spark Kryo: Register a custom serializer

血红的双手。 提交于 2019-11-29 03:57:58
I have a class that implements a custom Kryo serializer by implementing the read() and write() methods from com.esotericsoftware.kryo.Serializer (see example below). How can I register this custom serializer with Spark? Here is a pseudo-code example of what I have: class A() CustomASerializer extends com.esotericsoftware.kryo.Serializer[A]{ override def write(kryo: Kryo, output: Output, a: A): Unit = ??? override def read(kryo: Kryo, input: Input, t: Class[A]): A = ??? } val kryo: Kryo = ... kryo.register(classOf[A], new CustomASerializer()); // I can register my serializer Now in Spark: val

Java sun.misc.Unsafe详解

假装没事ソ 提交于 2019-11-29 00:30:51
Unsafe类在jdk 源码的多个类中用到,这个类的提供了一些绕开JVM的更底层功能,基于它的实现可以提高效率。但是,它是一把双刃剑:正如它的名字所预示的那样,它是Unsafe的,它所分配的内存需要手动free(不被GC回收)。Unsafe类,提供了JNI某些功能的简单替代:确保高效性的同时,使事情变得更简单。 这篇文章主要是以下文章的整理、翻译。 http://mishadoff.com/blog/java-magic-part-4-sun-dot-misc-dot-unsafe/ 1. Unsafe API的大部分方法都是native实现,它由105个方法组成,主要包括以下几类: (1)Info相关。主要返回某些低级别的内存信息:addressSize(), pageSize() (2)Objects相关。主要提供Object和它的域操纵方法:allocateInstance(),objectFieldOffset() (3)Class相关。主要提供Class和它的静态域操纵方法:staticFieldOffset(),defineClass(),defineAnonymousClass(),ensureClassInitialized() (4)Arrays相关。数组操纵方法:arrayBaseOffset(),arrayIndexScale() (5

Kryo serialization refuses to register class

与世无争的帅哥 提交于 2019-11-28 03:46:26
问题 I'm trying to use kryo serialization with: kryo.setRegistrationRequired(true); I keep getting the following error saying that a certain class is not registered: java.lang.IllegalArgumentException: Class is not registered: com.my.package.MyClass[] Note: To register this class use: kryo.register(com.my.package.MyClass[].class); However, I do register it: kryo.register(classOf[MyClass[_]]) When I set Log.TRACE() I get the following output: 00:11 TRACE: [kryo] Register class ID 51: com.my.package

Kryo serialization library: is it used in production?

假如想象 提交于 2019-11-28 03:34:24
Kryo is a very new and interesting Java serialization library, and one of the fastest in the thrift-protobuf benchmark. If you've used Kryo, has it already reached enough maturity to try it out in production code? Update (10/27/2010): We're using Kryo, though not yet in production. See my answer below for details. Update (3/9/2011): Updating to the latest Jackson and Kryo libraries shows that Jackson's binary Smile serialization is pretty competitive. NateS There is a bug report and a discussion thread . The DateSerializer that comes with Kryo is slightly more efficient size-wise than the

Spark Kryo: Register a custom serializer

对着背影说爱祢 提交于 2019-11-27 03:30:25
问题 I have a class that implements a custom Kryo serializer by implementing the read() and write() methods from com.esotericsoftware.kryo.Serializer (see example below). How can I register this custom serializer with Spark? Here is a pseudo-code example of what I have: class A() CustomASerializer extends com.esotericsoftware.kryo.Serializer[A]{ override def write(kryo: Kryo, output: Output, a: A): Unit = ??? override def read(kryo: Kryo, input: Input, t: Class[A]): A = ??? } val kryo: Kryo = ...

Flink 源码解析 —— 深度解析 Flink 是如何管理好内存的?

拈花ヽ惹草 提交于 2019-11-27 01:35:03
前言 如今,许多用于分析大型数据集的开源系统都是用 Java 或者是基于 JVM 的编程语言实现的。最着名的例子是 Apache Hadoop,还有较新的框架,如 Apache Spark、Apache Drill、Apache Flink。基于 JVM 的数据分析引擎面临的一个常见挑战就是如何在内存中存储大量的数据(包括缓存和高效处理)。合理的管理好 JVM 内存可以将 难以配置且不可预测的系统 与 少量配置且稳定运行的系统区分开来。 在这篇文章中,我们将讨论 Apache Flink 如何管理内存,讨论其自定义序列化与反序列化机制,以及它是如何操作二进制数据的。 数据对象直接放在堆内存中 在 JVM 中处理大量数据最直接的方式就是将这些数据做为对象存储在堆内存中,然后直接在内存中操作这些数据,如果想进行排序则就是对对象列表进行排序。然而这种方法有一些明显的缺点,首先,在频繁的创建和销毁大量对象的时候,监视和控制堆内存的使用并不是一件很简单的事情。如果对象分配过多的话,那么会导致内存过度使用,从而触发 OutOfMemoryError,导致 JVM 进程直接被杀死。另一个方面就是因为这些对象大都是生存在新生代,当 JVM 进行垃圾回收时,垃圾收集的开销很容易达到 50% 甚至更多。最后就是 Java 对象具有一定的空间开销(具体取决于 JVM 和平台)。对于具有许多小对象的数据集

Kryo serialization library: is it used in production?

拟墨画扇 提交于 2019-11-27 00:03:37
问题 Kryo is a very new and interesting Java serialization library, and one of the fastest in the thrift-protobuf benchmark. If you've used Kryo, has it already reached enough maturity to try it out in production code? Update (10/27/2010): We're using Kryo, though not yet in production. See my answer below for details. Update (3/9/2011): Updating to the latest Jackson and Kryo libraries shows that Jackson's binary Smile serialization is pretty competitive. 回答1: There is a bug report and a