JBoss EJB CMP2如何实现性能测试

发布时间:2021-12-03 09:29:27 作者:小新
来源:亿速云 阅读:163

这篇文章给大家分享的是有关JBoss EJB CMP2如何实现性能测试的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。



测试环境
操作系统:Win2000
CPU:PIII733EB
Memory:512M
Application Server:JBoss-3.0.2
DBMS:SAP DB7.3
Java VM:JDK-1.4.1
Ant:1.5.1[@more@]测试方案    
*表结构
表:AUX_TYPE
COLUMN名    SAP DB类型    Java类型
AUX_ID (Primary Key)    Integer    Integer
AUX_DESC    Varchar (50)    String

表:TEST_NEWS
COLUMN名    SAP DB类型    Java类型
TID    Integer    Integer
AUX_ID (Foreign key reference to AUX_TYPE(AUX_ID))    Integer    Integer
TNAME    Varchar (30)    String
TDESC    Varchar (100)    String
AMOUNT    Integer    Integer

*EJB结构
使用具有本地接口的EntityBean与表建立对应关系。使用一个无状态的SessionBean与客户端交互。SessionBean的作用是充当EntityBean的代理,并作为粗粒度的Bean提供远程数据访问。表AUX_TYPE主键的最大ID值也由SessionBean的(使用JDBC连接)方法提供。其他一些EJB QL不能实现,针对数据库特殊的查询方法同样可以在SessionBean中实现。
*测试代码

   private Category log = Category.getInstance(getClass());
   private AuxTypeHome auxTypeHome = null;
   private TestNewsHome testNewsHome = null;
   private Context initial = null;

   public void addNews(
       Integer tId,
       String tName,
       String tDesc,
       Integer amount,
       String auxDesc) {
       AuxType auxType = null;
       try {
           auxType = auxTypeHome.findByDesc(auxDesc);
           log.info("@@@@@@@@" + auxType.getAuxDesc());
           if (auxType == null)
               throw new EJBException("AUX_TYPE为空!");
       } catch (FinderException e) {
           throw new EJBException("findAuxType:" + auxDesc + "出错!");
       }
       try {
           TestNews testNews = testNewsHome.create(tId, tName, tDesc, amount);
           testNews.setAuxType(auxType);
       } catch (CreateException e) {
           throw new EJBException(
               "create TestNews:" + tId + "," + tName + "出错!");
       }

   }

   private Connection connection = null;
   private DataSource source = null;

   public synchronized int getNextId() throws RemoteException, SQLException {
       Statement stmt = null;
       int id = -1;
       try {
           if (initial == null)
               initial = new InitialContext();
           if (source == null)
               source = (DataSource) initial.lookup("java:/SapdbDS");
           if (connection == null)
               connection = source.getConnection();
           stmt = connection.createStatement();
           String sql = "select max(TID) from TEST_NEWS";
           ResultSet rs = stmt.executeQuery(sql);
           if (rs.next()) {
               id = rs.getInt(1);
               if (id <= 0) {
                   id = 1;
               }
           } else
               id = 0;
       } catch (NamingException e) {
       } finally {
           try {
               if (stmt != null)
                   stmt.close();
           } catch (Exception e) {
           }
       }
       return id + 1;
   }

   public Collection findNews(String find) {
       Collection news = null;
       try {
           news = testNewsHome.findAll();
       } catch (FinderException e) {
           throw new EJBException("findNews:" + find + "出错!");
       }
       return news;
   }

   public void removeNews(Integer tId) {
       try {
           testNewsHome.remove(tId);
       } catch (RemoveException e) {
           throw new EJBException("removeNews:" + tId + " 出错!");
       }
   }

   private void getHomes() throws NamingException {
       if (initial == null)
           initial = new InitialContext();
       auxTypeHome = getAuxTypeHome(initial);
       testNewsHome = getTestNewsHome(initial);
   }

   public void ejbCreate() throws CreateException {
       try {
           getHomes();
       } catch (NamingException e) {
           throw new CreateException("初始化SessionBean出错!");
       }
   }

   /**
    * @see javax.ejb.SessionBean#ejbActivate()
    */
   public void ejbActivate() throws EJBException, RemoteException {
   }

   /**
    * @see javax.ejb.SessionBean#ejbPassivate()
    */
   public void ejbPassivate() throws EJBException, RemoteException {
   }

   /**
    * @see javax.ejb.SessionBean#ejbRemove()
    */
   public void ejbRemove() throws EJBException, RemoteException {
       auxTypeHome = null;
       testNewsHome = null;
       initial = null;
       source = null;
       try {
           if (connection != null)
               connection.close();
       } catch (Exception e) {
       }
   }


*测试流程
客户端程序调用SessionBean的方法增加TEST_NEWS表的一行,TID值由ADO方法查询,数据库连接在ejbRemove方法中才释放,减少连接所需要的时间。对于AUX_DESC,通过findByDesc方法查询,如果查询不为空则增加一行,查询结果赋给TEST_NEWS的对象。

测试结果
操作:从AUX_TYPE查找按AUX_DESC匹配查询AUX_TYPE,新增200个TEST_NEWS
费时:11276ms

操作:从AUX_TYPE查找按AUX_DESC匹配查询AUX_TYPE,用JDBC DataSource从TEST_NEWS表中查找最大TID,新增200个TEST_NEWS
费时:15993ms
费时:12738ms(优化JDBC Connection)

同时笔者测试了在数据量不断增长时系统的性能,以下是结果:
插入行(插入前清空)    费时ms    费时ms (在已有行基础上插入10行)    内存占用,K
0        2214    22176
100    7200    1802    24452
200    12738    2894    34260
400    27499    2143    30600
600    50573    2704    33788
1000    134814    4226    51508

结论
当数据量倍增时,CMP表现出了接近成倍增加的资源消耗。这样的结果将最终表现出系统对大数据量不适应,无法满足要求。当笔者试图测试4000行数据时,经过数十分钟漫长的等待,数据停留在3000多行,客户端报内存溢出的错误,这时的内存占用接近100M。

感谢各位的阅读!关于“JBoss EJB CMP2如何实现性能测试”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. 从Jboss EAP 6.4迁移到EAP 7.1
  2. jboss6.1安装配置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ejb jboss

上一篇:C# Windows服务程序怎么开发

下一篇:tk.Mybatis插入数据获取Id怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》