频道栏目
首页 > 程序开发 > 软件开发 > Java > 正文
Spring的RMI , Http Invoker, Hessian测试结果
2012-04-10 09:08:08           
收藏   我要投稿

   RMI配置说明:

1:对象序列化:

public class Account implements Serializable{

    private String name;

    public String getName(){

        return name;

    }

    public void setName(String name) {

      this.name = name;

    }

}

2:远程接口定义:

public interface RemoteCallExample extends Remote {

      public String show() throws RemoteException;

}

3:远程接口实现:

public class RemoteCallExampleImpl implements RemoteCallExample {

      @Override

      public String show() throws RemoteException{

            return "remote test";

      }

}

4:Spring服务器端配置(使用RmiServiceExporter来):

在WEB-INF目录下面新建remoting-servlet.xml文件,添加相关的配置。

<bean name="remoteCallExample" class="com.hqb360.pay.service.impl.RemoteCallExampleImpl" />

<bean class="org.springframework.remoting.rmi.RmiServiceExporter">

          <!– does not necessarily have to be the same name as the bean to be exported –>

          <property name="serviceName" value="remoteCallExample"/>

          <property name="service" ref="remoteCallExample"/>

          <property name="serviceInterface" value="com.hqb360.pay.service.RemoteCallExample"/>

          <!– defaults to 1099 –>

          <property name="registryPort" value="1199"/>

</bean>

5:服务器端类

public class RemoteCallRMI{

      public String show() throws RemoteException{

            return remoteCallExample.show();

      }   

      private RemoteCallExample remoteCallExample;

      public RemoteCallExample getRemoteCallExample() {

            return remoteCallExample;

      }

      public void setRemoteCallExample(RemoteCallExample remoteCallExample) {

            this.remoteCallExample = remoteCallExample;

      }

}

6:服务器端配置

<bean name="remoteCallRMI" class="com.hqb360.pay.service.impl.RemoteCallRMI" >

            <property name="remoteCallExample" ref="remoteCall" />

</bean>

<bean id="remoteCall" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">

          <property name="serviceUrl" value="rmi://192.168.100.10:1199/remoteCallExample"/>

          <property name="serviceInterface" value="com.hqb360.pay.service.RemoteCallExample"/>

</bean>

     一些RMI问题说明:

1. RMI在启动配置中需要添加:-Djava.rmi.server.hostname=192.168.100.10

2. 需要制定相关的具体IP,把读取配置文件放到系统启动的时候处理。

Spring3.0后默认的HandlerMapping是DefaultAnnotationHandlerMapping,不是以前的BeanNameUrlHandlerMapping,所以配置Hessian和HttpInvoker的时候需要重新定义一下HandlerMapping.

在按照spring手册配置的时候需要添加定义(Spring文档有遗漏的地方):

<!–Hessian 启动BeanNameMapping 映射功能,以httpRequest作为处理Adapter–>

    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">

        <property name="defaultHandler" ref="httpRequestHandlerAdapter" />

    </bean>

    <!– Hessian 方式以Http进行传递 –>

    <bean id="httpRequestHandlerAdapter" class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />

     测试结果

测试性能:RMI > Hessian > Http Invoker

数据图表如下:

 

 

RMI

RMI并发测试(线程池大小:5,线程数:5)

[TestRunner] Starting executor timeOut:1000000ms workers:5 threadPoolSize:5

0 [5,880ms, 100%]

0 [5,881ms, 100%]

0 [5,977ms, 100%]

0 [5,978ms, 100%]

0 [5,989ms, 100%]

RemoteTestNG finishing: 8318 ms

RMI并发测试(线程池大小:5,线程数:10)

[TestRunner] Starting executor timeOut:1000000ms workers:10 threadPoolSize:5

0 [5,843ms, 100%]

0 [5,856ms, 100%]

0 [5,864ms, 100%]

0 [5,967ms, 100%]

0 [5,970ms, 100%]

0 [5,795ms, 100%]

0 [5,810ms, 100%]

0 [5,812ms, 100%]

0 [5,891ms, 100%]

0 [5,935ms, 100%]

RemoteTestNG finishing: 14194 ms

Httpinvoker

并发测试(线程池大小:5,线程数:5)

[TestRunner] Starting executor timeOut:100000ms workers:5 threadPoolSize:5

0 [24,350ms, 100%]

0 [25,384ms, 100%]

0 [27,601ms, 100%]

0 [27,700ms, 100%]

0 [29,443ms, 100%]

RemoteTestNG finishing: 31737 ms

并发测试(线程池大小:5,线程数:10)

[TestRunner] Starting executor timeOut:1000000ms workers:10 threadPoolSize:5

0 [26,519ms, 100%]

0 [26,637ms, 100%]

0 [28,365ms, 100%]

0 [29,744ms, 100%]

0 [29,821ms, 100%]

0 [28,433ms, 100%]

0 [29,914ms, 100%]

0 [31,795ms, 100%]

0 [28,959ms, 100%]

0 [29,407ms, 100%]

RemoteTestNG finishing: 61477 ms

hessian测试结果

并发测试(线程池大小:5,线程数:5)

[TestRunner] Starting executor timeOut:100000ms workers:5 threadPoolSize:5

0 [13,343ms, 100%]

0 [13,957ms, 100%]

0 [14,544ms, 100%]

0 [14,612ms, 100%]

0 [14,822ms, 100%]

RemoteTestNG finishing: 17133 ms

并发测试(线程池大小:5,线程数:10)

[TestRunner] Starting executor timeOut:100000ms workers:10 threadPoolSize:5

0 [13,407ms, 100%]

0 [14,058ms, 100%]

0 [14,271ms, 100%]

0 [14,293ms, 100%]

0 [18,198ms, 100%]

0 [14,496ms, 100%]

0 [15,128ms, 100%]

0 [16,478ms, 100%]

0 [17,680ms, 100%]

0 [17,317ms, 100%]

RemoteTestNG finishing: 37844 ms

 

需要测试代码的联系:longtask@gmail.com

 

摘自  longhao
点击复制链接 与好友分享!回本站首页
相关TAG标签 结果
上一篇:Struts2+hibernate+spring 配置文件中scope="prototype"的作用 .
下一篇:java中的移位运算
相关文章
图文推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站