|Many databases, same shared schema. One EntityManagerFactory? [message #1747555]
||Tue, 15 November 2016 21:52
| Miguel García López
Registered: November 2016
Hi, I am facing a problem on a legacy project I just inherited and written by not very experienced developers.|
We have a webapp deployed to a Tomcat instance and using EclipseLink 2.4.2 (could upgrade if required) to access a MySQL database (Amazon RDS).
Previous developers took the approach to *create a new database* for every new customer, all of them with the same schema definition. And then store these customer DBs names (schemas, or catalogs in MySQL parlance) somewhere.
The application creates *a new*, dedicated EntityManagerFactory for each customer session, store it into a Map[cust, emf] and remove it upon session expiration. We have a base persistence.xml and then set the specific DB name property at runtime when Persistence.createEntityManagerFactory(pu, props)-ing.
We now have > 1000 customers... the server eats loads of memory as you'll imagine and has the same number of DB connections to the server. This is of course not scalable. We're sort of screwed because we're growing
(we're planning to rewrite most of our data access layer and fix this, but we need something for the meantime because that'll be a daunting task)
Is there anything we could do with EclipseLink? I am thinking, maybe some way we could set our persistence.xml use a (Tomcat) DataSource to MySQL with no db name in the URL, and then setting the name (or schema, or catalog) in a per-case basis at runtime for each EntityManager we get.
Whether the above is feasible, and/or how to do it is unknown to me. I would be more than grateful if anyone here could help or maybe suggest an alternative approach.
Thanks a lot!
Powered by FUDForum
. Page generated in 0.01647 seconds