EF6/Glimpse - Connection takes much time when compared to the command execution - sql-server

We are trying to optimize the performance of our site. We are using glimpse for profiling and debugging. We noticed that the "connection opened" time in glimpse timeline is much higher when compared to the command execution time.
Load and number of connections in DB server seems to be normal. So we couldn't nail down the root cause.
As per Glimpse Timeline, the connection was opened for 381 ms. But the command got executed in 6 ms.
Total query execution time - 430 ms
Total connection open time - 19130 ms
Any idea why this happens?
Note :
Scope of DB Context is the scope of Http request
Number of records returned by these queries are < 1000 (approx)

.Net uses connection pooling and doesn't close connections. The only thing that matters is how long it took the EF method to return back to the caller. Do you have the DBContext instance in a "using" block to let .Net know to release it?

Related

Logic App - When connecting to on prem sql server: The gateway did not receive a response from 'Microsoft.Web' within the specified time period

I have a sql server database which has around 15 stored procedures and 4,73,000 tables. Every month the number of tables gets increased by around 500.
I have created a logic app and added a sql server action to execute a stored procedure which is available in this database. But when I am trying to see if the logic app is pointed to correct stored procedure from the designer view it is giving me the below exception. Also see the below screen shot.
The gateway did not receive a response from 'Microsoft.Web' within the specified time period.
When I verified the logs of on prem data gateway, the below exception is logged there.
Microsoft.Data.Mashup.MashupHostingException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation.
I tried to increase the RAM of the VM to 16GB still having the same issue.
Can anyone help me out is fixing the issue. I am unable to find the cause of the issue as well.
Thanks in advance.

C3P0 connections' health checks

I hope there is some expert on C3P0 that can help me answer the following question.
First, here's the general problem I'm trying to solve. We have an application connected to a database. When the database goes out, requests start taking several seconds to be processed, as opposed to a few milliseconds. This is because C3P0 will attempt to create new connections to the database. It will eventually timeout and the request will be rejected.
I came up with a proposal to fix it. Before grabbing a connection from the pool, I'll query C3P0's APIs to see if there are any connections in the pool. If there are none, we'll immediately drop the request. This way, our latency should remain in the milliseconds, instead of waiting until the timeout occurs. This solution works because C3P0 is capable of removing connections if it detects that they've gone bad.
Now, I set up a test with the values for "setTestConnectionOnCheckin" and "setTestConnectionOnCheckout" as "false". According to my understanding, this would mean that C3P0 would not test a connection (or, let's say, a connection in use, because there's also the idleConnectionTestPeriod setting). However, when I run my test, immediately after shutting off the database, C3P0 detects it and removes the connections from the pool. To give you a clearer picture, here's the execution's result:
14:48:01 - Request processed successfully. Processing time: 5 ms.
14:48:02 - Request processed successfully. Processing time: 4 ms.
14:48:03 - (Database is shut down at this point).
14:48:04 - java.net.ConnectException.
14:48:05 - Request rejected. Processing time: 258 ms.
14:48:06 - Request rejected. Processing time: 1 ms.
14:48:07 - Request rejected. Processing time: 1 ms.
C3P0 apparently knew that the database went down and removed the connections from the pool. It probably took a while, because the very first request after the database was shut off took longer than the others. I have run this test several times and that single request can take from 1 ms up to 3.5 seconds (which is the timeout time). This entry appears as many times as the number of connections I have defined for my pool. I have omitted all the rest for simplicity.
I think it's great that C3P0 is capable of removing the connections from the pool right away (well, as quickly as 258 ms. in the above example), but I'm having troubles explaining other people why that works. If "setTestConnectionOnCheckin" and "setTestConnectionOnCheckout" are set to "false", how is C3P0 capable of knowing that a connection went bad?
Even if they were set to "true", testing a connection is supposed to attempt executing a query on the database (something like "select 1 + 1 from dual"). We the database goes down, shouldn't the test timeout? In other words, shouldn't C3P0 take 3.5 seconds to determine that a connection has gone bad?
Thanks a lot, in advance.
(apologies... this'll be terse, i'm phonebound.)
1) even if no explicit Connection testing has been configured, c3p0 tests Connections that experience Exceptions while checked-out to determine whether they remain suitable for pooling.
2) a good JDBC driver will throw Exceptions quickly if the DBMS is unavailable. there's no reason why these internal Connection tests should be slow.
3) rather than polling for unused Connections to avoid waiting for checking / new acquisitions, you might consider just setting the config parameter checkoutTimeout.
good luck!

SQL Reporting services: First call is very slow

I've installed a SQL Reporting server (2008 R2), with some reports. But I've some performances issues.
The first call of the day to the server(going on the report interface by example), is VERY slow(something like 30-45seconds at best).
The report generation is then "fast"(1-2 seconds).
The next calls to the server are always fasts until the next day. I've the impression that it loads a lot of thing in the memory. But what can takes 30-45 seconds to be loaded in memory??? And how to load it only once?
The server is good enough(quad core, 8GB of ram, never near its capacity for now).
What is the problem? How can I resolve this ?
Thoses reports will be launched only 4-5 times in a week, so they will always be slow if I can't change this. And since it's available for customer, I just can't make them understand this(and the report is called through a website, so I risk to have timeout).
Thank you very much
It seems to be an SSRS issue. There is nothing wrong with your report.
It's "normal" that SSRS takes more time to load the first time you access it after a long time of inactivity. The issue is caused by the way how SSRS works and SSRS regularly restarts application domain after a specific time period. After the application domain is restarted, then upon first request to the SSRS it needs to load all the settings and it takes quite a long time.
This blog show's a workaround for the situation
Here is the powershell script that I wrote to fix the problem. It is setup as a task to run every 1:00am:
Stop-Service "SQL Server Reporting Services (MSSQLSERVER)"
Start-Service "SQL Server Reporting Services (MSSQLSERVER)"
$wc = New-Object system.net.webClient
$cred = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.Credentials = $cred
$src = $wc.DownloadString("http://localhost/Reports/Pages/Report.aspx?ItemPath=***NAME OF HOME PAGE***")
The best solution I could come up with was to issue a 'curl' command to the http page of the report using via windows batch command in a windows service. This ran up the page(s) every morning before the users came in.
Don't have access to the code anymore (job was a while ago) but this question shows how to use curl:
http://blogs.plexibus.com/2009/01/15/rest-esting-with-curl/
As Diego said, SSRS has some issues. The first call it is slow, regarding your server configuration. I recommend you the following config to add in rsreportserver.config (located if you don't know in C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer\ )
If you want to increase the max memory used by SSRS: (which means 7 GB)
<WorkingSetMaximum>7000000</WorkingSetMaximum>
If you want to improve the first call, you can set (in minutes)
<RecycleTime>4320</RecycleTime>
Actually SSRS has a reset (recycle) time in which cleans its buffer. By default its setted at 720 min (12h) so thats why if you open a report every morning it actually load very slow.
As you need you can set the recycle time higher (2-3 days). I don't recommend a higher time because the buffer will fill up and you will get only blank pages, so you will have to manually restart Reporting Services.
It may be completely unrelated to SQL Server. Try to see if is not the code sign revocation list check issue, see Fix slow application startup due to code sign validation
I converted the main query and the dropdown controls on the page to load from stored procedures, it made a difference of say 5 sec in the loading process.Avoid using any inline queries.

SQL Server Timeouts First Time Application Loads

I've recently switched to running my development environment over our company's VPN using NetExtender. It would now seem that my database driven applications are now timing out the first time they try to hit the database. After the timeout (30 sec or so) and an additional 5-10 seconds, all DB calls succeed. During the 5-10 seconds the timeout error response is sent immediately. It seems to be related to when SQL Server needs to create a new database session for me. Each time I need to be assigned a new client process ID, I timeout. This is a huge problem when using Resharper + NUnit as a test harness as each time the tests are run, a new instance of resharper's unit test runner is created thusly causing me to timeout. Server timeout seems to be in the area of 30 seconds, which is certainly generous enough for a connection to be established.
It sounds to me like it could be a DNS issue. If the primary DNS is not properly configured and is inaccessible from the VPN client, it will timeout and pass on to the secondary.
Additionally, some VPNs allow you to access some local resources - this could put the DNS on your own, local network in play.
I think I'd try changing the DNS-order and see if that did the trick.

System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

all
I am trying to resolve issue. where situation is,
There is asp.net webservice. webservice is connected with the sql server. created for receiving the data. but while requesting to the webmethod, even in browser i am getting exception :
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
AS per my understanding this must be issue about delaying in response from the server.Or due to time complexity in data fetching process in the method. I know we can specify the timeout for the sql command. but I don't have code access to change it. in short it is out of my scope to make change int he webservice code. how can i resolve this issue without editing any code. I can edit the web.config of webservice. but not code. please guide me.
Edited:
This issue is still there. but I am getting this issue on test server only. but on production server, it is running perfectly. I want to simulate this and want to resolve it on test server. because of this i am unable to proceed for next operation which is not present on the production server. why should this arriving here (on test server).
On test server i am changing the sql server name.
Because of this difference, we can conclude it should not be the issue in code. it must be issue /somewhere need setting in database side to define timeout or may be different . please guide me for the same.
You're gonna have to get someone who can change the code, increase the CommandTimeout (or set it to 0 for unlimited), and, more importantly, find out why the query takes so long.
If we set the timeout value to zero that means we are making sure that the operating will competed at any cost.

Resources