does connections count matter? - sql-server

We have an application that uses NHibernate to connect to our database on SQL Server.We use connection pooling and session per request approach to execute our queries over SQL Server.
We used SQL Server Activity Monitor to monitor connections count and noticed there was 25-30 connections involved whenever a user logged in to system.
So here's my question to ask : can large number of connections to SQL Server leads to performance issues?

Each connection to SQL Server requires the allocation of certain amount of memory and so there is a performance consideration in this regard.
In the scheme of things however, 20-30 connections is a very small number.
Have you validated that all connections belong to your application? The reason I ask is because SQL Server itself will establish and maintain a certain number of connections/sessions as part of the servers overall operation.
Some usefull DMV's for you to monitor:
select * from sys.dm_exec_connections
select * from sys.dm_exec_sessions
Session ID's above 51 are from outside of SQL Server so to speak, i.e. user sessions.
Further to comments:
SQL Server 2005 can support up to 32,767 connections. To check your capacity execute:
select ##MAX_CONNECTIONS
If connection pooling is being used then connections will remain open and in a sleep state until required for processing requests. Alternatively, perhaps the application is not closing connections when requests have finished processing.
I can only comment from a SQL Server perspective as I am not familiar with the mechanics of NHibernate.

Related

Go database client killing more connections to SQL Server than expected

As part of debugging some other issues on our server I noticed some really odd behavior with respect to connections that I'm hoping to understand.
I have 2 go servers, one of which talks to a SQL Server RDS instance, and another that talks to a managed SQL Server instance in Azure.
I believe there is a slight difference in the way the 2 backends work - RDS has a single port (1433) on which the client authenticates and subsequently establishes the connection. Azure SQL seems to authenticate on port 1433 and then redirect the client to another service that actually handles the connections.
In both cases I've got substantial load running against the servers. At least 500 requests/s, with peaks of about 2k req/s. Each of these requests results in a Select query which returns a single row with a primary key lookup - so really short lived connections to SQL. The average time per query is 50-80ms on both, with p95 in the 100-150ms range
Behavior I'm trying to understand:
I'm using the go database/sql driver with an MS-SQL implementation (Specifically go-mssqldb).
I've set Max Idle connections and Max Open connections to 64.
What I would expect: 64 long running Established connections that are occasionally idle but quickly reused.
What I'm seeing: Generally 64 Established connections, with the number often dropping down to somewhere between 50 and 64. This also results in 200-400 connections in the TIME_WAIT state at any given time.
What could be causing this behavior? It is just the fact that the go driver lazily closes connections? If so why would the number drop below 64?
I'm happy to provide any more details!

How connections to SQL Server 2012 are managed in ASP.NET MVC4 applications

I have a doubt about how a connection into SQL Server 2012 operates.
If is treated as per each request data.
or
If is treated as per session, when each user is connected (or the session is alive).
I need to know how many connections can stay alive depending on.
You should use one connection per request.
If you keep a connection per session, then you will limit the number of sessions to the maximum number of active connections. By using a connection per request you only need as many connections as there are threads handling requests, so the number of concurrent users is virtually unlimited.
Also, the server session ends a long time after the user actually left the site, which would further limit the number of concurrent users.
Even if the database can handle a lot of connections, it's a waste of resources to use a connection per session, and it causes a limitation that is completely unneccesary.

Need feedback!! Should enterprise level application can user one user to connect sql server database?

I am working on one large scale application (Web MVC Application), which can be used by enterprise level organizations later on where more than 50 or may be 100s of user are accessing the web at the same time and requesting data eventually to MS SQL Server.
My question is,
"Is it fine to use one user (in terms of connections and to fulfill all user requests) for all database connection by server side data access layer?"
What I mean is that whether there is any limit by MS SQL Server for one user to make number of connections simultaneously or not?
Your feedback will be very useful for me.
Thanks!!!
There is no limitation on the number of connections per user. Our website does this. All of our code accesses the database with one SQL Server credential.
There is, however, a hard limit on the total number of connections (around 30k) to the instance. We found this out the hard way with hundred of databases and connection pooling from tens of application servers.

SQL Server performance counter for incoming and outgoing bytes

For a project I need to read the incoming and outgoing bytes per second of an SQL-Server (2012) instance of an instance or database (doesn't matter). For this I found the following performance counters:
SQL Server, Broker / DBM Transport Object
Receive I/O bytes/sec
Send I/O bytes/sec
When starting SQL Server Management Studio and executing some select statements the values of the performance counters are staying 0. While when I included the client statistics I see that Bytes sent from client and Bytes sent from server are not 0. I'm executing these select statements to a default installed installed on the same pc.
Does anyone how to solve this issue?
Thanks in advance
The documentation explains what SQL Server, Broker / DBM Transport Object measures:
The Broker / DBM Transport performance object contains performance
counters that report networking information for Service Broker and
database mirroring.
There is no performance counter for Transact-SQL traffic. If it helps, the DMV sys.dm_exec_connections will aggregate the traffic size for a connection. If the traffic occurs over a network interface then you could use the system network counters, that is the Network Interface Object. But a local test would not register anything because the connection will use shared memory protocol.
That being said, it is unusual to have to measure SQL Server Transact-SQL network traffic. If the question ever arise, then you're doing it wrong. Network traffic should always be negligible. The dimension everybody is interested is IO, for which there is support in SQL Server, Buffer Manager Object, SQL Server, Databases Object and DMVs like sys.dm_io_virtual_file_stats.

SQL Connection Pooling and Audit Login/Logout

When I profile my application using SQL Server Profiler, I am seeing lots of Audit Login and Audit Logout messages for connections to the same database. I am wondering, does this indicate that something is wrong with my connection pooling? The reason I ask, is because I found this in the MSDN documentation in regards to connection pooling:
Login and logout events will not be
raised on the server when a connection
is fetched from or returned to the
connection pool. This is because the
connection is not actually closed when
it is returned to the connection pool.
For more information, see Audit Login
Event Class and Audit Logout Event
Class in SQL Server Books Online.
http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx
Also, does anyone have any tips for determining how effective the connection pooling is for a given SQL server? I have lots of databases on a single server and I know this can have a huge impact, but I am wondering if there is an easy way to obtain metrics on the effectiveness of my connection pooling. Thanks in advance!
While the MSDN article says that the event will only be raised for non-reused connections, the SQL Server documentation contradicts this statement:
"The Audit Login event class indicates that a user has successfully logged in to Microsoft SQL Server. Events in this class are fired by new connections or by connections that are reused from a connection pool."
The best way to measure the effectiveness of pooling is to collect the time spent in connecting with and without pooling. With pooling, you should see that the first connection is slow and the subsequent ones are extremely fast. Without pooling, every connection will take a lot of time.
If you want to track the Audit Logon event, you can use the EventSubClass data column to whether the login is with a reused connection or a new connection. The value will be 1 for a real connection and 2 for a reused connection from the pool.application.
Remember that connections are pooled per connectionstring. If you have many databases and connect using many connectionstrings, your app will create a new connection when none exist with the correct connectionstring. Then it will pool that connection and, if the pool is full, bump an existing connection. The default Max Pool Size is 100 connections, so if you're routinely bouncing through more than 100 databases, you'll close and open connections all the time.
It's not ideal, but you can solve the problem by always connecting to a single database (one connection string) and then switch db context 'USE [DBName]'. There are drawbacks:
You lose the ability to specify a user/pass per connection string (your app user needs permission to all databases).
Your SQL becomes more complex (especially if you're using an out-of-the-box ORM or stored procs).
You could experiment with increasing the Max Pool Size if your database count isn't huge. Otherwise, if some databases are used frequently while others aren't, you could turn pooling off on the infrequent dbs. Both items are configured via connectionstring.
As far as metrics, monitoring the login and logout events on SQL Server is a good start. If your app is pooling nicely you shouldn't see a lot of them.

Resources