简体   繁体   English

多租户:每个租户的单个数据库

[英]Multi-tenancy: Individual database per tenant

We are developing a multi-tenant application. 我们正在开发一个多租户应用程序。 With respect to architecture, we have designed shared middle tier for business logic and one database per tenant for data persistence. 在架构方面,我们为业务逻辑设计了共享中间层,为每个租户设计了一个数据持久性数据库。 Saying that, business tier will establish set of connections (connection pool) with the database server per tenant. 如果说,业务层将与每个租户的数据库服务器建立连接集(连接池)。 That means application maintain separate connection-pool for each tenant. 这意味着应用程序为每个租户维护单独的连接池。 If we expect around 5000 tenants, then this solution needs high resource utilization (connections between app server and database server per tenant), that leads to performance issue. 如果我们期望大约5000个租户,那么此解决方案需要高资源利用率(每个租户的应用服务器和数据库服务器之间的连接),这会导致性能问题。

We have resolved that by keeping common connection pool. 我们通过保持公共连接池来解决这个问题。 In order to maintain single connection pool across different databases, we have created a new database called 'App-master'. 为了在不同的数据库中维护单个连接池,我们创建了一个名为“App-master”的新数据库。 Now, we always connect to the 'App-master' database first and then change the database to tenant specific database. 现在,我们始终首先连接到“App-master”数据库,然后将数据库更改为特定于租户的数据库。 That solved our connection-pool issue. 这解决了我们的连接池问题。

This solution works perfectly fine with on-premise database server. 此解决方案与内部部署数据库服务器完美配合。 But it does not work with Azure Sql as it does not support change database. 但它不适用于Azure Sql,因为它不支持更改数据库。

Appreciate in advance to suggest how to maintain connection pool or better approach / best practice to deal with such multi-tenant scenario. 提前感谢建议如何维护连接池或更好的方法/最佳实践来处理此类多租户方案。

I have seen this problem before with multiple tenancy schemes with separate databases. 我在使用具有单独数据库的多个租赁方案之前已经看到过这个问题。 There are two overlapping problems; 有两个重叠的问题; the number of web servers per tenant, and the total number of tenants. 每个租户的Web服务器数量以及租户总数。 The first is the bigger issue - if you are caching database connections via ADO.net connection pooling then the likelihood of any specific customer connection coming into a web server that has an open connection to their database is inversely proportional to the number of web servers you have. 第一个是更大的问题 - 如果您通过ADO.net连接池缓存数据库连接,那么任何特定客户连接进入与其数据库具有开放连接的Web服务器的可能性与您的Web服务器数量成反比有。 The more you scale out, the more any given customer will notice a per-call (not initial login) delay as the web server makes the initial connection to the database on their behalf. 扩展得越多,当Web服务器代表他们建立与数据库的初始连接时,任何给定的客户都会注意到每次调用(而不是初始登录)延迟。 Each call made to a non-sticky, highly scaled, web server tier will be decreasingly likely to find an existing open database connection that can be reused. 对非粘性,高度扩展的Web服务器层进行的每次调用都将越来越不可能找到可以重用的现有开放数据库连接。

The second problem is just one of having so many connections in your pool, and the likelihood of this creating memory pressure or poor performance. 第二个问题只是在你的池中有这么多连接,并且这可能会造成内存压力或性能不佳。

You can "solve" the first problem by establishing a limited number of database application servers (simple WCF endpoints) which carry out database communications on behalf of your web server. 您可以通过建立有限数量的数据库应用程序服务器(简单WCF端点)来“解决”第一个问题,这些服务器代表您的Web服务器执行数据库通信。 Each WCF database application server serves a known pool of customer connections (Eastern Region go to Server A, Western Region go to Server B) which means a very high likelihood of a connection pool hit for any given request. 每个WCF数据库应用程序服务器服务于已知的客户连接池(东部区域转到服务器A,西部区域转到服务器B),这意味着对于任何给定请求,连接池的可能性非常高。 This also allows you to scale access to the database separately to access to HTML rendering web servers (the database is your most critical performance bottleneck so this might not be a bad thing). 这也允许您单独扩展对数据库的访问以访问HTML呈现Web服务器(数据库是您最关键的性能瓶颈,因此这可能不是一件坏事)。

A second solution is to use content specific routing via a NLB router. 第二种解决方案是通过NLB路由器使用特定于内容的路由。 These route traffic based on content and allow you to segment your web server tier by customer grouping (Western Region, Eastern Region etc) and each set of web servers therefore has a much smaller number of active connections with a corresponding increase in the likelihood of getting an open and unused connection. 这些路由流量基于内容,允许您通过客户分组(西部地区,东部地区等)对您的Web服务器层进行分段,因此每组Web服务器的活动连接数量都少得多,相应增加了获取的可能性。一个开放和未使用的连接。

Both these problems are issues with caching generally, the more you scale out as a completely "unsticky" architecture, the less likelihood that any call will hit cached data - whether that is a cached database connection, or read-cached data. 这两个问题一般都是缓存问题,你越是扩展为一个完全“不粘”的架构,任何调用都会降低缓存数据的可能性 - 无论是缓存数据库连接还是读缓存数据。 Managing user connections to allow for maximum likelihood of a cache hit would be useful to maintain high performance. 管理用户连接以允许高速缓存命中的最大可能性对于保持高性能是有用的。

Another method of restricting the number of connection pools per app server is to use Application Request Routing (ARR) to divide up your tenants and assign them to subsets of the web tier. 限制每个应用服务器的连接池数量的另一种方法是使用应用程序请求路由(ARR)来划分您的租户并将它们分配给Web层的子集。 This lends itself to a more scalable "pod" architecture where a "pod" is a small collection of web/app servers coupled to a subset of the databases. 这有助于实现更具伸缩性的“pod”架构,其中“pod”是耦合到数据库子集的web / app服务器的小集合。 A good article on this approach is here: http://azure.microsoft.com/blog/2013/10/31/application-request-routing-in-csf/ 这里有一篇关于这种方法的好文章: http//azure.microsoft.com/blog/2013/10/31/application-request-routing-in-csf/

If you are building a multi-tenant DB application Azure you should also check-out the new Elastic Scale client libraries that simplify data-dependent routing and facilitate cross-shard queries and management operations. 如果要构建多租户数据库应用程序Azure,则还应检出新的Elastic Sc​​ale客户端库,这些库可简化数据相关的路由并促进跨分片查询和管理操作。 http://azure.microsoft.com/en-us/documentation/articles/sql-database-elastic-scale-documentation-map/ http://azure.microsoft.com/en-us/documentation/articles/sql-database-elastic-scale-documentation-map/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们可以在多租户中使用 DbContext 池(EF Core)吗 每个租户的单个数据库 - Can we use DbContext pool (EF Core) in multi tenancy Individual database per tenant 多租户系统中租户控制队列并发 - Control queue concurrency by tenant in multi-tenancy system 为多租户配置 Razor 页面,使用 IPageRouteModelConvention 和单独的租户页面文件夹 - Configure Razor Pages for multi-tenancy, using IPageRouteModelConvention and separate tenant page folders 虚拟导航属性和多租户 - Virtual Navigation Properties and Multi-Tenancy 实体框架多租户和动态模式 - Entity Framework Multi-Tenancy and dynamic schema 具有过滤的dbContext的多租户Web应用程序 - Multi-tenancy web application with filtered dbContext 具有ASP.NET身份的实体框架多租户 - Entity Framework Multi-Tenancy with ASP.NET Identity 使用 Azure 服务总线重新总线、竞争消费者和多租户 - Rebus with Azure Service Bus, Competing consumers and multi-tenancy 在运行时从子域设置EF ConnectionString以进行多租户设置 - Set EF ConnectionString at runtime from subdomain for multi-tenancy setup EF6 中的多租户具有多个具有相同表的架构 - Multi-tenancy in EF6 with multiple schemas having the same tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM