英文:
What is the difference between Concurrent Login and Concurrent Session?
问题
背景信息
在一个使用 Hikari 连接池连接到关键业务 Azure SQL Server 实例的 Spring 应用程序上工作。
Azure DB 实例方面的限制如下:
- 200 个工作进程
- 200 个登录用户
- 3 万个会话
我们部署了 3 台应用服务器,每台都使用了 Hikari 连接池。
据我所知:
- 应用程序的 Hikari 连接池会根据需要打开新的 TCP 连接,并将它们池化以供 Spring Data / Hibernate 等使用。
- 应用程序视角下的 SQL 连接会使用连接字符串来建立与服务器的 TCP 连接,通过该连接传输协议数据(包括认证)和 SQL 查询。
- 根据上述限制,TCP 连接的数量不受限制。
- 在我理解中,工作进程是实际执行针对数据库的 SQL 查询并检索结果的进程/线程。
- 一个查询/语句可能会使用多个工作进程,如果可以并行执行的话。
- (尽管尚未找到文档)可以很容易地看出,登录用户受工作进程的限制,因为无论谁登录并希望与数据库交互,都需要一个执行语句的工作进程,该工作进程使用登录用户的安全上下文执行语句。
- 根据这个链接:"会话是指同时允许连接到 SQL 数据库的并发连接数。工作进程可以被看作是在处理查询的 SQL 数据库中的进程。允许的最大会话和工作进程数取决于数据库的服务层级。"
问题
- 在没有其他应用程序连接到数据库的情况下,Spring 应用程序是否可以使用相同的用户名和密码创建大约 3 万个连接或 200 个连接?
- 在这种情况下,Azure SQL 登录 / Azure SQL 会话应如何解释?
注意:我知道我可以通过启动 N 个应用程序来进行测试并监视行为,我感到沮丧的是我找不到相关的文档,帮助我自己回答这个问题。
英文:
Background information
Working on a Spring application with Hikari Connection Pooling that is connecting to Business Critical Azure SQL Server Instance.
The limitations on Azure's side of the DB instance are:
- 200 Workers
- 200 Logins
- 30k Sessions
We have 3 application servers deployed with a Hikari CP.
As far as I know:
- The application's Hikari connection pool is opening new TCP connections as they are needed and pooling them for spring data / hibernate / etc.
- An SQLConnection from the application's POV is using the Connectionstring to build a TCP connection to the server through which the protocol data (incl. authentication) and sql queries will be transmitted
- According to the limitations listed above the number of TCP connections is not limited
- In my understanding workers are processes/threads that actually execute SQL queries against the database and retrieve results.
- One query/statement might use multiple workers, if it can be parallelized
- (although haven't find the documentation) It is easy to see that the Logins are capped by the workers because whoever logs in, and wants to interact with the DB will need a worker that is executing the statements that is provided with the security context of the logged in user
- According to this: "Sessions refers to the number of concurrent connections allowed to a SQL database at a time. Workers can be thought of as the processes in the SQL database that are processing queries. The maximum number of sessions and workers allowed depends on your databases’s service tier."
Questions
- Can the spring applications make a total of ~30k connections or ~200 connections (assuming no other application connects to the database) with the same username and password?
- How shall Azure SQL Login / Azure SQL Session be interpreted in this context?
Note: I am aware that I can test this by launching N applications to connect and monitor the behavior, what I am frustrated about is how I cannot find the relevant documentation that could help me answer the question for myself.
答案1
得分: 1
你对于工作机制的理解是正确的。
登录是与服务器进行主动认证的用户。遇到这个问题的情况相当少见,但如果您的架构涉及大量的断开/重新连接类型的操作,可能会发生这种情况。在这种情况下,用户名/密码并不重要。您只是不希望尝试同时启动 200 个应用程序实例。
虽然遇到登录限制的情况相当罕见,但需要注意的是会话限制。Hikari 创建的池中的每个连接在 Azure SQL 一侧都计为一个会话。也就是说,如果只有 3 台服务器,您可以在每个池中打开 10,000 个连接,不会有问题。除非您做了一些阻止 Hikari 在需要时正确关闭连接的操作,否则现在可能不会对您构成问题。我对 Hikari 不是特别熟悉,所以无法为您提供导致这种情况的具体示例。
英文:
Your understanding of workers is correct.
Logins are users actively authenticating with the server. It's pretty rare to run into this issue, but it can happen if your architecture involves a lot of disconnect/reconnect type actions. Username/Password doesn't matter in this context. You just don't want to try to spin up 200 instances of your application at the same time.
While it's pretty rare to run into the login limit, running into the session limit is something you need to keep an eye on. Each connection that Hikari creates in the pool counts as a session on the Azure SQL side. That being said, with only 3 servers, you could open 10k connections in each pool and be fine. Probably not an issue for you right now unless you do something that prevents Hikari from properly closing connections when it needs to. I'm not too familiar with Hikari, so I can't give you a specific example of what would cause this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论