- 浏览: 2477381 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Object Pool对象池化技术
并非所有对象都适合拿来池化??因为维护对象池也要造成一定开销。对生成时开销不大的对象进行池化,反而可能会出现“维护对象池的开销”大于“生成新对象的开销”,从而使性能降低的情况。但是对于生成时开销可观的对象,池化技术就是提高性能的有效策略了。
This is my ObjectFactory using object pool:
import org.apache.commons.pool.KeyedPoolableObjectFactory;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.GenericKeyedObjectPool.Config;
public class StateMachineFactory implements KeyedPoolableObjectFactory
{
private static GenericKeyedObjectPool _objectPool = null;
public Object makeObject(Object key) throws Exception
{
ResumeableVendorOrderProcessor resumeableVendorOrderProcessor = null;
Class aClass = null;
if ((null != key))
{
try
{
aClass = Class.forName("the process class name, you need change this", true, this.getClass().getClassLoader());
resumeableVendorOrderProcessor = (ResumeableVendorOrderProcessor) aClass.newInstance();
}
catch (Exception e)
{
Log.error(this, "makeObject() exception:" + e);
}
}
return (resumeableVendorOrderProcessor);
}
public void destroyObject(Object key, Object object) throws Exception
{
}
public boolean validateObject(Object key, Object object)
{
return (true);
}
public static ResumeableVendorOrderProcessor getNewInstance(Object key)
{
Log.info(StateMachineFactory.class, "getNewInstance() - key: " + key);
ResumeableVendorOrderProcessor resumeableVendorOrderProcessor = null;
Class aClass = null;
if ((null != key))
{
try
{
aClass = Class.forName("the process class name, you need change this");
resumeableVendorOrderProcessor = (ResumeableVendorOrderProcessor) aClass.newInstance();
}
catch (Exception e)
{
Log.error(StateMachineFactory.class, "getNewInstance() exception:" + e);
}
}
return (resumeableVendorOrderProcessor);
}
synchronized public static ResumeableVendorOrderProcessor getInstance(Object key)
{
ResumeableVendorOrderProcessor resumeableVendorOrderProcessor = null;
String vendorId = "";
try
{
if (null == _objectPool)
{
initObjectPool(false);
}
if ((null != key) && (null != _objectPool))
{
vendorId = (String) key;
if (vendorId != null && !"".equals(vendorId))
{
resumeableVendorOrderProcessor = (ResumeableVendorOrderProcessor) _objectPool.borrowObject(vendorId);
}
}
}
catch (Throwable e)
{
Log.error(StateMachineFactory.class, "makeObject() exception:" + e);
}
return (resumeableVendorOrderProcessor);
}
synchronized public static void returnInstance(Object key, ResumeableVendorOrderProcessor resumeableVendorOrderProcessor)
{
String vendorId = null;
if ((null != key) && (null != _objectPool))
{
try
{
vendorId = (String) key;
Log.info(StateMachineFactory.class, "returnInstance() - Returning " + key);
_objectPool.returnObject(vendorId, resumeableVendorOrderProcessor);
}
catch (Throwable aThrowable)
{
aThrowable.printStackTrace();
}
}
}
synchronized public static void initObjectPool(boolean forceInit)
{
Log.info(StateMachineFactory.class, "initObjectPool()");
Config poolConfiguation = null;
if ((null == _objectPool) || forceInit)
{
_objectPool = new GenericKeyedObjectPool(new StateMachineFactory());
poolConfiguation = getPoolConfiguration();
_objectPool.setConfig(poolConfiguation);
}
}
private static Config getPoolConfiguration()
{
Log.info(StateMachineFactory.class, "getPoolConfiguration()");
Config poolConfiguration = new Config();
// Per key
poolConfiguration.maxActive = 25;
// For entire pool
poolConfiguration.maxTotal = 2500;
return (poolConfiguration);
}
public void activateObject(Object key, Object object) throws Exception
{
Log.info(StateMachineFactory.class, "activeObject");
}
public void passivateObject(Object key, Object object) throws Exception
{
Log.info(StateMachineFactory.class, "passivateObject");
}
}
We can call getInstance and returnObject to use object in pool
Everytime you returnObject, you need confirm that the object is stateless, or you need to re-init them.
并非所有对象都适合拿来池化??因为维护对象池也要造成一定开销。对生成时开销不大的对象进行池化,反而可能会出现“维护对象池的开销”大于“生成新对象的开销”,从而使性能降低的情况。但是对于生成时开销可观的对象,池化技术就是提高性能的有效策略了。
This is my ObjectFactory using object pool:
import org.apache.commons.pool.KeyedPoolableObjectFactory;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.GenericKeyedObjectPool.Config;
public class StateMachineFactory implements KeyedPoolableObjectFactory
{
private static GenericKeyedObjectPool _objectPool = null;
public Object makeObject(Object key) throws Exception
{
ResumeableVendorOrderProcessor resumeableVendorOrderProcessor = null;
Class aClass = null;
if ((null != key))
{
try
{
aClass = Class.forName("the process class name, you need change this", true, this.getClass().getClassLoader());
resumeableVendorOrderProcessor = (ResumeableVendorOrderProcessor) aClass.newInstance();
}
catch (Exception e)
{
Log.error(this, "makeObject() exception:" + e);
}
}
return (resumeableVendorOrderProcessor);
}
public void destroyObject(Object key, Object object) throws Exception
{
}
public boolean validateObject(Object key, Object object)
{
return (true);
}
public static ResumeableVendorOrderProcessor getNewInstance(Object key)
{
Log.info(StateMachineFactory.class, "getNewInstance() - key: " + key);
ResumeableVendorOrderProcessor resumeableVendorOrderProcessor = null;
Class aClass = null;
if ((null != key))
{
try
{
aClass = Class.forName("the process class name, you need change this");
resumeableVendorOrderProcessor = (ResumeableVendorOrderProcessor) aClass.newInstance();
}
catch (Exception e)
{
Log.error(StateMachineFactory.class, "getNewInstance() exception:" + e);
}
}
return (resumeableVendorOrderProcessor);
}
synchronized public static ResumeableVendorOrderProcessor getInstance(Object key)
{
ResumeableVendorOrderProcessor resumeableVendorOrderProcessor = null;
String vendorId = "";
try
{
if (null == _objectPool)
{
initObjectPool(false);
}
if ((null != key) && (null != _objectPool))
{
vendorId = (String) key;
if (vendorId != null && !"".equals(vendorId))
{
resumeableVendorOrderProcessor = (ResumeableVendorOrderProcessor) _objectPool.borrowObject(vendorId);
}
}
}
catch (Throwable e)
{
Log.error(StateMachineFactory.class, "makeObject() exception:" + e);
}
return (resumeableVendorOrderProcessor);
}
synchronized public static void returnInstance(Object key, ResumeableVendorOrderProcessor resumeableVendorOrderProcessor)
{
String vendorId = null;
if ((null != key) && (null != _objectPool))
{
try
{
vendorId = (String) key;
Log.info(StateMachineFactory.class, "returnInstance() - Returning " + key);
_objectPool.returnObject(vendorId, resumeableVendorOrderProcessor);
}
catch (Throwable aThrowable)
{
aThrowable.printStackTrace();
}
}
}
synchronized public static void initObjectPool(boolean forceInit)
{
Log.info(StateMachineFactory.class, "initObjectPool()");
Config poolConfiguation = null;
if ((null == _objectPool) || forceInit)
{
_objectPool = new GenericKeyedObjectPool(new StateMachineFactory());
poolConfiguation = getPoolConfiguration();
_objectPool.setConfig(poolConfiguation);
}
}
private static Config getPoolConfiguration()
{
Log.info(StateMachineFactory.class, "getPoolConfiguration()");
Config poolConfiguration = new Config();
// Per key
poolConfiguration.maxActive = 25;
// For entire pool
poolConfiguration.maxTotal = 2500;
return (poolConfiguration);
}
public void activateObject(Object key, Object object) throws Exception
{
Log.info(StateMachineFactory.class, "activeObject");
}
public void passivateObject(Object key, Object object) throws Exception
{
Log.info(StateMachineFactory.class, "passivateObject");
}
}
We can call getInstance and returnObject to use object in pool
Everytime you returnObject, you need confirm that the object is stateless, or you need to re-init them.
发表评论
-
Update Site will come soon
2021-06-02 04:10 1605I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 374Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 368Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 318Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 393VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 293Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 328PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 580Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 226Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 248Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 194MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 239MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 278Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 263Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 285Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 232Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 284K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 315Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 395Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 330Redis Cluster 2019(3)Redis Clus ...
相关推荐
相信不少人听过 boost 委员会提过 boost 里的对象池设计存在缺陷。我花了一些时间研究它的实现,发现其在效率上确实存在严重问题。这里给出一套解决方案。...可以完全替换你项目里的 object_pool。
演示了如果您的对象需要从一个Factory构造,或当你的对象是用Emit生成时,如何简单继承ObjectPool类,实现特殊的对象的池化操作。
使用此工具类,对于Object和byte[] 数组, 16进制和String之间的转换
### get-keypool Object Pool get-keypool使用单个 arity 函数来创建对象。 ( def pool ( get-keypool ( fn [k] ( str :heavy k)))) ( borrow pool :object ) ; => ":heavy:object" ; Return key and object ( ...
Unity3D内置对象池对应案例以及源码 包含两个场景不同的效果展示了使用以及未使用对象池的差距
Unity 工具类 之 简单的对象池管理类 ObjectPoolManager 实现 1、单例类,保证整个场景中只有一个类管理对象池; 2、把需要的对象以对象池形式管理起来,需要的时候 拿出来显示即可,不需要的时候隐藏以来即可; ...
UE4 对象池插件 Actor对象池
object c 语言面向对象编程教程, 描述了object c语言是如何实现面向编程的
jQuery EasyUI 1.2.6 解决无法遮罩object对象的问题,在代码第1862行增加iframe对象遮罩object对象。
Java代码Map转Object对象
FunctionObject_函数对象
SAP ABAP OBJECT 面向对象开发 (IBM官方培训教程)
本文实例讲述了JavaScript创建一个object对象并操作对象属性的用法。分享给大家供大家参考。具体分析如下: 下面的JS代码创建了一个myMovie对象,并给对象title和director属性赋值,通过Object定义对象,其属性可以...
Dual-Object Dual-Object 面向对象的并行程序设计面向对象的并行程序设计
lockfree-object-pool = " 0.1 " extern crate lockfree_object_pool; 例子 一般的池创建看起来像这样 let pool = LinearObjectPool :: < u32> :: new ( || Default :: default (), | v | { * v = 0 ; }); 并...
Java代码Object对象转Map
java中Object对象String对象的解析.pdf
【OMT介绍】 OMT(object modeling techniques)简单描述 对象模型:描述对象、类及其相互之间关系的静态数据结构;...Java编程 OMT(object modeling techniques)对象 动态 功能 10 部署图(共16页).ppt
NULL 博文链接:https://bijian1013.iteye.com/blog/2310135