多租户接缝 + JPA申请
我正在开发一个现有的 Seam 2.2.0 + JPA (Hibernate 3.3.1) 应用程序,该应用程序需要转换为“每个客户端单个数据库”环境,其中每个数据库模式都相同。该应用程序在 Glassfish 上运行,使用 IceFaces,并且有几个使用 Conversations 的页面。它还使用单个 EJB 进行身份验证。不幸的是,将客户拆分到他们自己的数据库中的决定超出了我的控制范围。
作为概念证明,我已经使用 Spring JPA 抽象、资源本地事务和上下文信息的 ThreadLocal 将 EntityManagerFactory 和 DataSource 的管理移至应用程序中,从而使应用程序能够识别多个数据库。例如,每次用户登录时,都会使用新的 DataSource 来初始化新的 EntityManagerFactory,该新的 DataSource 会与其数据库进行通信(如果尚未初始化)。这在具有少量数据库的测试环境中运行良好。
我的问题是,这种方法可以扩展到数百个数据库吗?我希望将应用程序服务器添加到负载均衡器来处理额外的负载,但是与典型的服务器相比,Hibernate/JPA 一级缓存和/或 Seam 上下文管理(也称为内存消耗)的开销需要更多的服务器来扩展负载平衡应用程序?如果是这样,是否可以通过分配具有大量 RAM 和/或大型分布式缓存的服务器来缓解这一问题?
任何见解将不胜感激。
I work on an existing Seam 2.2.0 + JPA (Hibernate 3.3.1) application that needs to be converted to a 'single database per client' environment where each database schema is the same. The application runs on Glassfish, uses IceFaces, and has several pages that utilize Conversations. It also uses a single EJB for authentication. Unfortunately, the decision to split clients off into their own databases is outside of my control.
As a proof of concept, I have already made the application aware of multiple databases by moving the management of EntityManagerFactory(ies) and DataSource(s) into the application using Spring JPA abstractions, resource local transactions, and ThreadLocal for context information. For example, each time a user logs in a new EntityManagerFactory is initialized using a new DataSource that communicates with their database if it has not already been initialized. This is working well in a test environment with a handful of databases.
My question is, will this approach scale to hundreds of databases? I expect to add application servers to a load balancer to handle additional load, but will the overhead of the Hibernate/JPA first-level cache and/or Seam context management (a.k.a., memory consumption) require significantly more servers to scale compared to a typical load balanced application? If so, can this be mitigated by allocating servers with lots of RAM and/or a large distributed cache?
Any insight would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用这种方法开发了一个应用程序,我可以指出的是:
EntityManagerFactory
(HibernateSessionFactory
) 实例,每个实例都需要大量的 RAM。I worked on an application with this approach and I what I can point out is:
EntityManagerFactory
(HibernateSessionFactory
) each requiring a considerable amount of Ram.hibernate.cache.region_prefix
configuration parameter to make these names uniques among the various instances using the database id as the cache prefix.