Java序列化与Kryo序列化的优缺点是什么? [英] What are the pros and cons of java serialization vs kryo serialization?

查看:202
本文介绍了Java序列化与Kryo序列化的优缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在spark中,java序列化是默认设置,如果kryo效率很高,那么为什么不将其设置为默认设置.使用kryo有什么缺点吗?在什么情况下应该使用kryo或Java序列化?

In spark, java serialization is the default, if kryo is that efficient then why it is not set as default. Is there some cons using kryo or in what scenarios we should use kryo or java serialization?

推荐答案

此处是文档:

Kryo比Java序列化显着更快,更紧凑(通常多达10倍),但不支持所有Seri​​alizable类型并要求您在以下位置注册要在该计划中使用的课程前进以获得最佳性能.

Kryo is significantly faster and more compact than Java serialization (often as much as 10x), but does not support all Serializable types and requires you to register the classes you’ll use in the program in advance for best performance.

因此默认情况下不使用它,因为:

So it is not used by default because:

  1. 并非开箱即用地支持每个 java.io.Serializable -如果您具有扩展 Serializable 的自定义类,除非已注册,否则仍无法使用Kryo进行序列化.
  2. 需要注册自定义类.
  1. Not every java.io.Serializable is supported out of the box - if you have custom class that extends Serializable it still cannot be serialized with Kryo, unless registered.
  2. One needs to register custom classes.

根据文档的注释:

Spark自动为许多产品包括Kryo序列化器从以下版本的AllScalaRegistrar中涵盖的常用Scala核心类 Twitter chill 库.

这篇关于Java序列化与Kryo序列化的优缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆