Java與Python的CORBA解決方案執行效率實測對比 (转)

2012年5月3日 stone 没有评论

因為最近及以後一些項目開發語言和環境逐步要向Java、Python上切,所以過年這幾天就花了點功夫研究了一下Java和Python,特別是對它們之間的互操作進行了研究。

由於我在HW從事電信系統開發,用CORBA用得比較多,所以就着重研究了一下兩者在CORBA方面的解決方案。

具體來講,做了以下實驗:

實驗環境:DUO2330 2×1.6GHz, 2G, WindowsXP SP3, JDK1.6.0, Python2.6/omniORBpy-3.3

第一階段:

* 用Python/omniORBpy實現CORBA服務端

* 用Python/omniORBpy實現CORBA客戶端

* 使用omniNames名字服務器實現Python CORBA服務的發布和調用

第二階段:

* 用Java/org.omg.CORBA實現CORBA服務端

* 用Java/org.omg.CORBA實現CORBA客戶端

* 使用jdk/tnameserv名字服務器實現Java CORBA服務的發布和調用

第三階段:

* 使用ACE/TAO的nameservice實現Python CORBA服務的發布和調用

* 使用jdk/tnameserv名字服務器實現Python CORBA服務的發布和調用

* 使用Python CORBA客戶端調用Java CORBA服務

* 使用Java CORBA客戶端調用Python CORBA服務

第四階段:

* 測試Python CORBA客戶端調用Python CORBA服務的執行效率

* 測試Python CORBA客戶端調用Java CORBA服務的執行效率

* 測試Java CORBA客戶端調用Python CORBA服務的執行效率

* 測試Java CORBA客戶端調用Java CORBA服務的執行效率

實驗結果如下:

一、解決方案完整性:

* 使用Python/omniORBpy可以無障礙實現服務器、客戶端、名字服務器 – OK

* 使用Python/omniORBpy可以正確編譯TMF814指定的標準IDL文件 – OK

* 使用Java/org.omg.CORBA可以無障礙實現服務器、客戶端、名字服務器 – OK

* 使用Java/org.omg.CORBA可以正確編譯TMF814指定的標準IDL文件 – OK

二、互操作性:

* Python/omniORBpy可以正常使用ACE/TAO的nameservice – OK

* Python/omniORBpy可以正常使用jdk/tnameserv名字服務器 – OK

* 使用Python CORBA客戶端調用Java CORBA服務 – OK

* 使用Java CORBA客戶端調用Python CORBA服務 – OK

三、執行效率:

1、Java客戶端調用Java CORBA服務:

69秒/100000次, 1449次/秒

CPU佔用率: server=32%, client=27%

2、Java客戶端調用Python CORBA服務:

40秒/100000次, 2500次/秒

CPU佔用率: server=11%, client=43%

3、Python客戶端調用Java CORBA服務:

34秒/100000次, 2941次/秒

CPU佔用率: server=35%, client=9%

4、Python客戶端調用Python CORBA服務:

11秒/100000次, 9091次/秒

CPU佔用率: server=23%, client=18%
四、初步結論:

* Python/omniORBpy和Java/org.omg.CORBA都可以提供CORBA應用解決方案,但從技術完整性和社區資源來看,Java的支持要好於Python。

* Python/omniORBpy開發效率要高於Java,代碼更簡潔。

* Python/omniORBpy和Java/org.omg.CORBA的互操作性很好。

* 執行效率上Python/omniORBpy明顯高於Java/org.omg.CORBA,純Python/omniORBpy(客戶端、服務器都使用Python實現)效率比純Java/org.omg.CORBA的效率高627%!—-不知如果使用INOA Orbix或VisiBroker效率會不會明顯提升?—-有經驗的朋友可以幫忙解答一下這個問題。

說明:以上是我初步的實驗結論,因為也是剛接觸CORBA不久,所以可能有所偏頗,歡迎各位專家共同探討!

分享家:Addthis中国
分类: 未分类 标签:

使用omniORBpy开发简单CORBA程序 (转)

2012年5月3日 stone 没有评论

使用omniORBpy开发简单CORBA程序

创建时间:2005-11-04 更新时间:2005-11-05
文章属性:原创
文章提交:r00t (shanleiguang_at_gmail.com)

CORBA被认为是企业级应用采取的技术,但发展到现在已经存在许多开源的CORBA软件,如Linux操作系统的桌面管理系统Gnome就是使用开源的ORBit开发。本文将介绍如何使用omniORBpy 和Python脚本语言来开发简单的CORBA程序,希望对大家理解和掌握CORBA技术有所帮助。

>CORBA编程的基本概念

>>对象请求代理ORB(Object Request Broker)与接口定义语言IDL(Interface Defination Language)。

>>对象的引用(Object Reference)唯一定位分布的对象,是一个字符串。

>>客户程序(Client)可以直接使用对象引用定位、访问活动的服务对象。

>>命名服务(Naming Service)是定位分布对象的最佳手段,命名服务负责将对象的逻辑名解析为该对象的引用字符串,称为名字解析(Name resolving),可以联系主机域名和DNS服务器来理解。

>>服务程序(Servant)将服务对象注册到命名服务器并和一个逻辑名绑定,客户程序可以从命名服务器获得该服务对象逻辑名的对象引用字符串。

>>对象逻辑名由名字组件(Name compoment)组成,名字组件由ID、Kind两个域组成。

>>名字上下文(Name context)中包含对象逻辑名绑定的集合,同时一个名字上下文也可绑定到另一个名字上下文中,则对象逻辑名的绑定包括两类:对普通对象名的绑定和对一个名字上下文的绑定。

>>POA是服务程序与ORB(Object Request Broker)之间的媒介,提供对对象的管理、适配和Object Key的分配。

>omniORBpy简介

工欲善其事、必先厉其器,进行CORBA开发你需要选择一个ORB和一种熟悉的编程语言,对于学习者而言,omniORBpy和Python就是一对很好的组合。omniORB的官方网站(http://omniorb.sourceforge.net)上是这样介绍omniORB的:omniORB is a robust high performance CORBA ORB for C++ and Python. It is freely available under the terms of the GNU Lesser General Public License (for the libraries), and GNU General Public License (for the tools).

>Python简介

事实上我个人偏爱Perl这只“骆驼”-Perl在网络编程、文本解析和数据库处理方面的表现非常出色,可惜它对CORBA的支持一直做的不够好。Python这条“蟒蛇”在国外很流行,据说Yahoo是靠Perl起家、而Google则是靠的Python。Python是面向对象的脚本开发语言,语法非常精简,容易上手。

>配置omniORBpy的开发环境

操作系统是Windows XP SP2,这样我就可以方便的一边调试这些脚本、一边编辑这篇文档,当然顺便再来点Music。

1、安装Python解释环境
a)到http://www.activestate.com 下载ActivePython2.4;
b)安装到C:\Python24目录下即可;

2、安装omniORBpy
a)到http://omniorb.sourceforge.net下载omniORBpy2.6,选择下载已经使用VC++编译好的二进制版本(如果使用C++编程则下载omniORB);
b)从源代码编译omniORBpy时,需要omniORB的C++库,则还需要下载omniORB的源代码,操作系统上也要有VC++的编译环境;
c)下载完后解压到C:\omniORBpy目录下;

3、配置环境变量
a)首先将C:\omniORBpy\bin\x86_win32目录添加到环境变量PATH中,这样在命令行下就可以直接运行omniORBpy提供的命令,如用于编译IDL文件的omniidl和提供命名服务的omninames等;
b)PYTHONPATH变量是Python搜索模块的路径集合,将C:\ominiORBpy\lib\python和C:\omniORBpy\lib\x86_win32添加到PYTHONPATH中,使得Python可以搜索到omniORBpy提供的CORBA编程模块;
c)omniORB首先会读OMNIORB_CONF环境变量找配置文件,如果未设置该环境变量则到注册表的”HKEY_LOCAL_MACHINE/Software/omniORB”位置下读取相关配置信息;
d)“我的电脑-属性-高级-环境变量”中可以编辑环境变量;

4、配置命名服务器
若程序要用到命名服务,则可在创建命名服务对象时指定命名服务器的地址,也可以在注册表中添加。例如要使用本地的命名服务器“NameService”,则在HKEY_LOCAL_MACHINE/Software/omniORB/下创建名为“InitRef”,类型为字符串,值为“NameService=corbaname::localhost”的子键,在后面的例子中会看到如何使用命名服务绑定和解析对象逻辑名。

>CORBA编程基本步骤

1、编写IDL接口描述文件;
2、将IDL编译成所用开发语言的库,如C++、Java、Python,omniORBpy用于编译IDL的命令为omniidl;
3、配置并启动Naming Service(可选),omniORBpy命名服务的命令为omninames;
4、编写服务程序,在命名服务器上绑定对象IOR的逻辑名;
5、编写客户程序,访问命名服务器解析对象逻辑名的IOR;

>omniORBpy编程实例

设工作目录%WORKDIR%为C:\omniORBpy\scripts\messenger。

>>Example One:使用对象引用字符串定位对象

Step1.编写IDL接口定义文件

—bof:secret_messenger.idl—
Module messenger
{
Interface SecretMessage
{
String get_message();
};
};
—eof—

Step2.使用omniidl命令将IDL文件编译成Python模块

生成包括客户程序(Client)使用的Stubs(存根?)和服务程序(Servant)使用的Skeleton(骨架?),在Step1中定义了一个仅包含一个方法的SecretMessage接口,遵照OMG组织发布的Python的映射规范-IDL中定义的接口将被映射到Python的若干类中。
secret_messenger_idl.pyc,客户程序使用的Stubs在messenger文件夹中,服务程序使用的Skeleton在messenger__POA文件夹中,这样做的好处在于当接口扩展时便于扩展模块。
%WorkDir%>omniidl –bpython secret_messenger.idl

Step3.编写CORBA服务程序
(1)、Servant需要以Skeleton中的框架类为父类,定义包括了具体实现的服务类,并创建服务对象的实例。
(2)、再向Servant端的ORB注册(发布)该对象,联系基本概念中对POA的描述-POA是Servant与ORB之间管理Object的媒介,向ORB注册、激活对象需要用到POA对象。则首先要创建并初始化ORB对象请求代理和POA(Portable Object Adaptor),使用POA Manager对象向ORB服务注册并激活SecretMessage对象。POA对服务程序而言非常重要,它是用于管理服务程序中所有可用对象的那个对象(在面向对象的程序设计中一切都是对象,除此之外没有别的),每个POA对象拥有自己的POA Manager,用于管理所有注册的对象。
(3)、创建了服务对象实例,启动ORB服务组件,获取了RootPOA Manager,接下来就要向ORB激活对象实例,激活的方法OurSecretMessage类已经从messenger__POA.SecretMessage类中继承获得,即_this()方法。本例中将服务对象的IOR字符串值写入message.ior文件中,我们可以通过Email的方式将IDL文件和message.ior文件发布给客户程序开发者。

—bof:messenger_server.py—
#!C:\Python24\python.exe
#以Skeleton类为基类,定义服务类的实现
import messenger, messenger__POA
class OurSecretMessage(messenger__POA.SecretMessage):
def __init__(self, secret_message):
self.secret_message = secret_message

def get_message(self):
return self.secret_message

#创建服务对象实例
ourMessage = ourSecretMessage(“Hello, omniORBpy!”)

#初始化ORB、POA、POA_MANAGER对象
import sys
from omniORB import CORBA

orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
poa = orb.resolve_initial_references(“RootPOA”)
poa_manager = poa._get_the_POAManager()
poa_manager.activate()

#激活对象,对象的类从messenger_POA中继承了激活的方法_this()
message_obj = ourMessage._this()

#将对象引用字符串IOR写入message.ior文件
output_handle = open(“message.ior”, “w”)
string_ior = orb.object_to_string(message_obj)
output_handle.write(string_ior)
output_handle.close()

#启动ORB
orb.run()
—eof—

Step4.编写客户脚本
从message.ior文件读取服务对象的IOR,将IOR对象化,调用服务对象的方法get_message(),将得到”Hello, omniORBpy!”字符串;

—bof:messenger_client.py—
#!C:\Python24\python.exe
import sys
from omniORB import CORBA
import messenger

#从message.ior文件读取服务对象的IOR
input_handle = open(“message.ior”, “r”)
ior = input_handle.read()
input_handle.close()

orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)

#从IOR获取对象,导入到自己地址空间中
obj = orb.string_to_object(ior)
mo = obj._narrow(messenger.SecretMessage)

result = mo.get_message()
print result
—eof—

Step4.运行情况

(1)、启动服务程序
%WORKDIR%>messenger_server.py
(2)、启动客户程序
%WORKDIR%>messenger_client.py
Hello, omniORBpy!
(3)、在message.ior文件中存储者Servant激活对象的IOR
—bof:message.ior—
IOR:010000002000000049444c3a6d657373656e6765722f5365637265744d6573736167653a312e3000010000000000000064000000010102000c00000031302e33312e3230302e38005b0d00000e000000fe8db26a4300000d20000000000000000200000000000000080000000100000000545441010000001c00000001000000010001000100000001000105090101000100000009010100
—eof—

现在只要把messenger.idl和meeage.ior文件发布给客户程序的开发者,客户程序可以从网络中任何位置获取这条消息了。

>>Example two:使用命名服务定位分布的对象

Example one中将对象的IOR写入文件中发布,这样做很不方便,如当服务对象的IOR改变时就要重新发布IOR。想象一下互联网中域名服务器是怎样工作的:SP申请IP地址和域名,在域名服务器注册域名;用户要访问该域名,首先到域名服务器解析其IP地址,再访问该IP地址;当SP的IP地址改变时只要在域名服务器更新注册的IP地址即可,用户端依然可以使用域名访问。对象逻辑名和CORBA命名服务,就可以类比域名和域名服务器来理解。

(1)、修改messenger_server.py中初始化orb、poa的部分

—bof:messenger_server.py—
#!C:\Python24\python.exe
import sys
import CORBA
import messenger, messenger__POA

class OurSecretMessage(messenger__POA.SecretMessage):
def __init__(self, secret_message):
“”"Intialize with the secret message we’re going to use.
“”"
self.secret_message = secret_message

def get_message(self):
return self.secret_message

our_message = OurSecretMessage(“I don’t want any spam!”)

#初始化ORB、POA、POA_Manager对象
import sys
from omniORB import CORBA

#ORB初始化时,会接受命令行中”-ORB”开始的参数,这里指定命名服务器地址
sys.argv.extend((“-ORBInitRef”, “NameService=corbaname::localhost”))
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)

poa = orb.resolve_initial_references(“RootPOA”)
poa_manager = poa._get_the_POAManager()
poa_manager.activate()

#初始化命名服务对象
import CosNaming

name_service_obj = orb.resolve_initial_references(“NameService”)
name_service_root = name_service_obj._narrow(CosNaming.NamingContext)
assert name_service_root is not None, “Failed to narrow to NamingContext.”

#激活对象
message_obj = our_message._this()

#将对象绑定到逻辑名”Messenger.SecretMessage”
message_name = [CosNaming.NameComponent("Messenger", "SecretMessage")]
name_service_root.bind(message_name, message_obj)
print “Bound the Message Object to naming service”

print “Server is running”
orb.run()
—eof—

(2)、修改客户程序
—bof:messenger_client.py—
#!C:\Python24\python.exe
import sys
from omniORB import CORBA
import CosNaming
import messenger

#初始化客户ORB,指定访问的命名服务器地址
sys.argv.extend((“-ORBInitRef”, “NameService=corbaname::localhost”))
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)

#获取命名服务对象,解析服务对象的逻辑名Messenger.SecretMessage
name_service_obj = orb.resolve_initial_references(“NameService”)
name_service_root = name_service_obj._narrow(CosNaming.NamingContext)
assert name_service_root is not None, “Failed to narrow to NamingContext.”

message_name = [CosNaming.NameComponent("Messenger", "SecretMessage")]
message_obj = name_service_root.resolve(message_name)
result = message_obj.get_message()

print result
—eof—

(3)、运行情况

(a)、首先启动命名服务
C:\>omninames
omniORB: Warning: the local loop back interface (127.0.0.1) is used as this server’s address. Only clients on this machine can talk to
this server.

Fri Nov 04 09:59:43 2005:
Read log file successfully.
Root context is IOR:010000002b00000049444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f6e746578744578743a312e30000001000000000000005c000000010102000a0000003132372e302e302e3100f90a0b0000004e616d6553657276696365000200000000000000080000000100000000545441010000001c00000001000000010001000100000001000105090101000100000009010100
Checkpointing Phase 1: Prepare.
Checkpointing Phase 2: Commit.
Checkpointing completed.
… …

(b)、启动服务程序,到omninames绑定逻辑名

C:\Python24\Scripts\messenger>secret_message_srv.py
omniORB: Warning: the local loop back interface (127.0.0.1) is used as this server’s address. Only clients on this machine can talk to
this server.
Bound the Message Object to naming service
Server is running
… …

(c)、启动客户程序,到omninames解析逻辑名

C:\Python24\Scripts\messenger>secret_message_clt.py
Hello, omniORBpy!

分享家:Addthis中国
分类: 未分类 标签:

ACE/TAO/CIAO/DAnCE x.1.0 minor release available for downloa

2012年3月9日 stone 没有评论

ACE/TAO/CIAO/DAnCE x.1.0 minor release available for downloa
新版本支持vxworks 6.9

分享家:Addthis中国
分类: 未分类 标签:

问:如何启动SSHd服务?

2012年2月27日 stone 没有评论

答:

#rpm -qa |grep ssh 检查是否装了SSH包
#chkconfig –list sshd 检查SSHD是否在本运行级别下设置为开机启动
#chkconfig –level 2345 sshd on  如果没设置启动就设置下.
#service sshd restart  重新启动
#netstat -antp |grep sshd  看是否启动了22端口.确认下.
#iptables -nL  看看是否放行了22口.
#setup—->防火墙设置   如果没放行就设置放行.

分享家:Addthis中国
分类: 未分类 标签:

OpenDDS version 3.0.1 发布

2011年11月22日 stone 没有评论

The DCPSInfoRepo reassociates Built in Topic connections for existing
datareaders and datawriters when restarted from persistence.

- The opendds_idl compiler will now print a warning about not including
TAO’s orb.idl file when a file named orb.idl is included.

- Fixed a bug where the timeout for passive_connect_duration was
ignored.

- Fixed multiple bugs in fragmentation/reassembly used for udp and
multicast.

- Fixed multicast loopback and session re-use problems.

- Fixed a bug with memory management for the TransportCustomizedElement
used in publisher-side content filtering.

- New example Messenger.minimal – which is like messenger, but
streamlined for new users to understand the whole easier.

分享家:Addthis中国
分类: 未分类 标签:

OpenDDS 3.0发布

2011年8月22日 stone 没有评论

OpenDDS 3.0发布.
可以用配置 文件 配置传输层;
SimpleTCP 改名为tcp,增加了 Excel的Add-in。

分享家:Addthis中国
分类: 未分类 标签:

OpenDDS 2.3发布

2011年2月20日 stone 没有评论

OpenDDS 2.3于2011年2月18日发布。

(Stone Jiang 编译)

  • OpenDDS 建模开发库  (SDK)首次在本版中发布。使用该建模工具,应用程序员可以像使用UML建模工具那样定义中间件组件的需求和数据结构,然后生成相应的代码。生成的代码可以直接编译和链接进应用程序从而对应用程序提供无缝支 持。这里用到的建模工具用到的图形编译器是基于Eclips实现的。
  • 使用Built-in Topic (内置主题时),DCPSInfoRepo 不再使用-ORBSvcConf 参数。而DCPSInfoRepo会谨慎的加载SimpleTCP库(当其未被加载时)
  • 支持for Microsoft Visual Studio 2010 (vc10).
分享家:Addthis中国
分类: OpenDDS 标签:

转贴:在centos中编译安装emacs23

2011年2月12日 stone 没有评论

Emacs 22 or 23 installation/upgrade possibility?
#5
Newbie

Joined: 2010/4/18
From
Posts: 6
1. Download the emacs-23.2.tar.gz package
a) open Konqueror
Konqueror &

b) navigate to http://ftp.gnu.org/pub/gnu/emacs

c) download emacs-23.2.tar.gz to the desired directory

d) untar the tarball by entering the following command:
tar xvf emacs-23.2.tar.gz

e) change directory to the new emacs-23.2 directory that was created by the untar
cd /FullPath/emacs-23.3

2. Update packages on RHEL or CentOS Linux
From a Konsole window enter the following commands:
yum -y groupinstall “Development Tools”
yum -y install gtk+-devel gtk2-devel
yum -y install libXpm-devel
yum -y install libpng-devel
yum -y install giflib-devel
yum -y install libtiff-devel libjpeg-devel
yum -y install ncurses-devel
yum -y install gpm-devel dbus-devel dbus-glib-devel dbus-python
yum -y install GConf2-devel pkgconfig
yum -y install libXft-devel

3. Build the emacs installation files
Within the emacs-23.2 directory enter the following commands at the Konsole:
./configure –prefix=/usr/local –with-x-toolkit=gtk
make
make install
Emacs 23.2 should now be installed.

Credit where it is due:

http://blog.penzilla.net/2010/07/emacs-on-centos-5.html

分享家:Addthis中国
分类: 未分类 标签:

Readline Error: readline/readline.h: No such file or directory

2010年11月18日 stone 没有评论

Let’s take a simple readline program
#include
#include
#include

int main() {
char *s;
s= readline(NULL);
printf(“characters read: %s\n”, s);
}

On compiling this program
$ gcc readInput.c
readline.c:2: fatal error: readline/readline.h: No such file or directory
compilation terminated.

If you come across this error, you must install readline dev package
$ sudo apt-get install libreadline6 libreadline6-dev

分享家:Addthis中国
分类: 未分类 标签:

ACE+TAO+CIAO+DAnCE x.8.3 available for download

2010年10月28日 stone 没有评论

ACE+TAO+CIAO+DAnCE x.8.3 available for download

==============
Changes to ACE
==============

阅读全文…

分享家:Addthis中国
分类: ACE, TAO 标签: