• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > 关于分布式程序 java的内存管理浅谈,java内存管理浅谈

关于分布式程序 java的内存管理浅谈,java内存管理浅谈

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含浅谈java,浅谈漏罪的程序处理,浅谈abaqus用户子程序,浅谈泊松分布及其应用,浅谈正态分布等服务器相关知识,网友希望可以进行参考

关于分布式程序 java的内存管理浅谈,java内存管理浅谈


关于分布式程序 java的内存管理浅谈

标签(空格分隔): 分布式 内存管理 java


Preface

当前全球正处于互联网时代,是个信息大爆炸时代。对于商家来说,每一天信息都是宝贵的,都可以转换成money的。所以对数据的处理要求也变的越来越严格,从以前的hadoop/MapReduce 的离线处理,到现在的准实时和实时处理,都是由数据需求而引起的技术革命。数据的处理快慢取决于很多因素。现在主流的解决方法,像Spark,Flink,Pular,包括腾讯,阿里,百度的诸多为开源的框架都是基于分布式内存的大数据处理计算框架,所以内存的使用变的很关键。由于各个框架都是基于JVM语言开发的,所以JVM的内存管理问题被提上日程。

Java AutoBoxing and UnBoxing

提到Java大家都会想到AutoBoxing和UnBoxing,这项技术最早是在jdk1.5引入进来的。AutoBoxing是java编译器的自动转换过程,针对primitive和与之对应的object wrapper类之间的自动转换,例如把int转换为Integer,double转换为Double等等。反之呐就是Unboxing。
虽然Boxing技术给开发人员带来了很多方便,但是也带来了问题——内存的问题

所有的primitive 的Object 类型都是继承于Object类的,如果调用new Object(), object没有任何其他可存储的成员,那么它也会占用8个字节的内存。

大家都知道C语言中字节是4字节对齐的,那么java也是字节对齐的,不过是8字节对齐的。类的成员变量声明的先后顺序也能影响该类所占的内存大小。

在现今的大数据处理时代,为了能够提高实时性,很多数据直接在内存中不落地的,所以内存占用很大,也会造成一定效率问题。

这个autoboxing的问题很早之前就已经有人提出来了,有个开源的lib叫fastutil是针对java的autoboxing和unboxing做了优化的。读者可以自行下载源码看看。

Programming based on Memory

上学时图书馆有本书貌似叫《Programming based on Limited Memory》,内容讲的是在移动设备上编程,很老的一本书,那个时候的移动设备内存最大才1M,一般都是512K居多,现在这个Programming based on Limited Memory概念仍然是需要的。

之前Spark提出来基于内存RDD的计算模式,在其documents上对于Memory Tuning有几条建议:

There are three considerations in tuning memory usage: the amount of memory used by your objects (you may want your entire dataset to fit in memory), the cost of accessing those objects, and the overhead of garbage collection (if you have high turnover in terms of objects).

By default, Java objects are fast to access, but can easily consume a factor of 2-5x more space than the “raw” data inside their fields. This is due to several reasons:

  • Each distinct Java object has an “object header”, which is about 16 bytes and contains information such as a pointer to its class. For an object with very little data in it (say one Int field), this can be bigger than the data.
  • Java Strings have about 40 bytes of overhead over the raw string data (since they store it in an array of Chars and keep extra data such as the length), and store each character as two bytes due to String’s internal usage of UTF-16 encoding. Thus a 10-character string can easily consume 60 bytes.
  • Common collection classes, such as HashMap and LinkedList, use linked data structures, where there is a “wrapper” object for each entry (e.g. Map.Entry). This object not only has a header, but also pointers (typically 8 bytes each) to the next object in the list.
  • Collections of primitive types often store them as “boxed” objects such as java.lang.Integer.

摘自Tuning Spark

还有一点关于In-Process Memory 和Distributed Memory的对比:


2.Overheads
  • In-Process Memory, This dated but very descriptive article describes how an in-process cache can negatively effect performance of an application with an embedded cache primarily due to garbage collection overheads. Your results however are heavily dependent on factors such as the size of the cache and how quickly objects are being evicted and timed-out.
  • Distributed caches, A distributed cache will have two major overheads that will make it slower than an in-process cache (but better than not caching at all): network latency and object serialization
  • Commnets , As described earlier, if you are looking for an always-consistent global cache state in a multi-node deployment, a distributed cache is what you are looking for (at the cost of performance that you may get from a local in-process cache).
3.Reliability
  • In-Process Memory, An in-process cache makes use of the same heap space as your program so one has to be careful when determining the upper limits of memory usage for the cache. If your program runs out of memory there is no easy way to recover from it.
  • Distributed caches,A distributed cache runs as an independent processes across multiple nodes and therefore failure of a single node does not result in a complete failure of the cache. As a result of a node failure, items that are no longer cached will make their way into surviving nodes on the next cache miss. Also in the case of distributed caches, the worst consequence of a complete cache failure should be degraded performance of the application as opposed to complete system failure.
  • Commnets, An in-process cache seems like a better option for a small and predictable number of frequently accessed, preferably immutable objects. For large, unpredictable volumes, you are better off with a distributed cache.
摘自 In-Process Caching vs. Distributed Caching

Open Project Solutions


对比Flink和Presto的内存管理,你会发现Flink用了一个固定的32byte申请管理内存,而Presto用了一个叫Slice来做快速的heap和off-heap操作。


上述如有不对的地方还请指正,小弟将不胜感激。 转载请注明出处,谢谢

Reference

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 关于分布式程序 java的内存管理浅谈,java内存管理浅谈

相关文章

  • openstack中glance组件images的所有python API 汇总,openstackglance
  • 在Windows上使用Eclipse配置Hadoop MapReduce开发环境,hadoopmapreduce
  • Hadoop之—— CentOS Warning: $HADOOP_HOME is deprecated解决方案,hadoopdeprecated
  • Spark性能优化:shuffle调优
  • Install Docker on Mac OS X,installdocker
  • 大数据的两种处理方式,数据两种处理方式
  • 《转》OpenStack Keystone的基本概念理解,《转》openstack
  • NOSQL(三)分布式数据模型,nosql模型
  • Hadoop学习总结,hadoop总结
  • hive 实现job并发执行,hive实现job并发

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • **FASPOT 功能简介**,faspot功能简介
    • python模块,python
    • myeclipse2013 建的web项目没有web.xml,myeclipse中web.xml
    • Sqoop导入数据到Hadoop代理执行,sqoophadoop
    • 开源微内核seL4 microkernel,sel4microkernel
    • 大数据学习笔记1--hadoop简介和入门,学习笔记1--hadoop
    • Andrew Ng机器学习课程9-补充,andrew9-
    • Spark 基于item和user 的协同过滤实现,sparkitem
    • linux screen 使用方法,linuxscreen
    • HDFS命令行接口详解,hdfs命令行详解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有