ICE-高效的中间件平台,牛刀小试

ICE(Internet Communications Engine)是ZeroC提供的一款高性能的中间件,基于ICE可以实现电信级的解决方案。前面我们提到过在设计网站架构的时候可以使用ICE实现对网站应用的基础对象操作,将基础对象操作和数据库操作封装在这一层,在业务逻辑层以及表现层(java,php,.net,python)进行更丰富的表现与操作,从而实现比较好的架构。基于ICE的数据层可以在未来方便的进行扩展。ICE支持分布式的部署管理,消息中间件,以及网格计算等等。

大道理讲完,言归正传,最近育儿网新增了不少新服务,服务间经常会需要相互调用数据,例如用户中心要取博客系统里的文章啊,论坛里发文后要在积分系统里增加用户积分啊。由于设计时这些服务仅仅基于统一的用户中心,服务间基本是独立的,所以要实现这些调用只能在每个服务上新增为其它服务提供服务的服务-_-!。这个时候有几个可选方案,我们开始选择了xml-rpc,基于http和xml的选程调用,用了一段时间,发现维护成本和访问性能都存在问题。

由于这些中间服务部署的时候是和各自所属的服务部署在一起的,对这些服务做整体的改动就非常困难,要维护起来就比较麻烦。另外由于是什么http和xml作为通信协议,由php实现业务逻辑,性能问题也很明显,而且这些http请求都会在http日志留下足迹,导致我们的日志分析很不精确。这个问题不是太大,但很郁闷,所以我们考虑使用ICE来解决这个问题,至于SOAP什么的就不考虑了,同样效率低下。

实现的过程还是比较顺利,花了三天的时间用c++实现了大部分常用的接口,服务端采用deamon的方式运行,错误日志记在syslog里(/var/log/messages),客户端PHP,编译进去了IcePHP,调用的方法很简单。现在还存在一些问题,运行的时候会异常退出,还需要一段时间来解决,暂时加了只狗看着,一旦进程里没了就重新启动。

既然要跨平台通讯,就涉及对象描述,ICE使用Slice来对结构,类,方法等进行定义。完了以后服务器端,客户端都按这个来调用和实现。ICE内置的Linux 下后台Deamon实现方案非常简单,只需要从Ice::Service里派生出一个类来,实现run方法,在这个方法里创建adapter对象,并在adapter对象里添加Servants,然后激活这个adapter就可以了,网络层的通信都由ICE接管了。由于是基于tcp/ip的直接通信,比更高层的http通信效率要高很多。

在客户端实现时,我们也碰到了一些小麻烦。一个是内置的$ICE对象用的时候有时需要用global声明,否则可能会出错,另外由于默认情况下Slice中struct对应到php的类型是一个类的实例,而不是一个数组,所以在赋值给页面的时候,smarttemplate以及其它模板系统中可能都会存在问题,可以通过修改模板系统的数据赋值显示代码解决。

我们做了一些性能的测试,同样运行1千次请求,使用xml-rpc实现需要28秒左右,使用ICE实现,只需要3秒多,性能的差距还是很大的,同时在这个过程中没发现有内存泄露的情况,效果还比较理想。

最后感慨一下,ICE是适合人类使用的中间件!

Subscribe

Related articles

Interpreting Marriage in Dreams: Good or Bad

Dreaming of marriage can symbolize unity or commitment in waking life. It may reflect a desire for partnership or emotional fulfillment. However, it could also represent anxieties about commitment or fears of loss of freedom. Remember that dream interpretations are subjective and can vary based on personal beliefs and experiences.

Romantic NYC Date Ideas: 10 Perfect Spots to Impress Your Date

Looking for a special date idea in NYC? From picnics in Central Park to sunset cocktails in Brooklyn, there are countless romantic spots to explore with your special someone. Let's discover the best options for an unforgettable date night in the Big Apple.

Who Should Attend the Bridal Shower? Your Complete Guide

The bridal shower is a special occasion where the bride is surrounded by her close family and friends. Traditionally, the guest list includes the bridal party, close relatives, and female friends who will celebrate with the bride ahead of her big day.

Ultimate Bach Party Gifts for the Bride-to-Be

Are you looking for the perfect gifts to celebrate the bride-to-be at her bachelorette party? From personalized items to pampering sets, we have the top picks to make her feel special before her big day.

Unveiling the Mystery: What is a Promise Ring and Its Romantic Significance

A promise ring is a symbol of commitment between couples. It represents a promise to be faithful and to one day marry. It is a romantic gesture that signifies a deep and meaningful relationship.

Enchanting Veil Hairstyles to Complete Your Bridal Look

Discover the elegance and romance of veil hairstyles. From soft waves to intricate updos, veils can be the perfect addition to any bridal look.

Unveiling the Magic of a Day-of Coordinator

A day of coordinator is like a behind-the-scenes magician, ensuring that every detail of your special day runs smoothly. They orchestrate the events with grace and precision, so you can focus on the romance and joy of your wedding day.

Unveiling the Magic of a Bridal Shower: What You Need to Know

A bridal shower is a cherished pre-wedding tradition where the bride-to-be is showered with love, gifts, and well wishes from close friends and family. It's a time for celebration and laughter as the bride prepares for her big day.
spot_imgspot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here