Query performance when running on Tomcat 6.0 - sql

I am facing a weird problem when running a simple aggregation query form my application within Tomcat.
The query is a PreparedStatement - select Min([VSZ(Bytes)]) 'Maximum Resident Memory Utilized (MB)',Min([RSS(Bytes)]) 'Maximum Virtual Size memory (MB)' ,Min([%CPU])'Total CPU Utilization %'from ps_ where ([cmd_date]) > = ? and ([cmd_date]) < = ? and zone = ? and command like ?
This is taking more than 6 mins to complete.
When i run this query from SQL server Studio, it completes within a minute.
To further troubleshoot the problem i wrote a simple java class which creates connection and executes the same query. It is not running on Tomcat but it on the same server on which Tomcat is running.
This also completes within a minute.
I am not an expert on Tomcat, what could i be missing?

Related

Why does running the query through JDBC take longer than the time reported by EXPLAIN

I have a SQL query, first I analyzed the query by executing and it is taking less than 1 ms.
So I used the query in my spring boot app, and tried to execute it using
namedParameterJdbcTemplate.query(sqlQuery, params, new validationMapper());
but when I see the time, it is 19212ms.
Why this much time difference?

Max out Azure SQL DTU with SQL inside code, but not from SQL Server Management Studio

I have a bit a funny situation. Our Azure SQL instance maxes out at 100 DTU for a certain query and the query returns a timeout:
SqlException (0x80131904): Timeout expired. The timeout period
elapsed prior to completion of the operation or the server is not
responding. This failure occurred while attempting to connect to the
routing destination.
If I run exactly the same query (with the parameters hardcoded) in SQL Server Management Studio it still takes the DTU up to 25%, but that's still far away from 100%. Nothing else runs on that server. There are a few other queries that run before/after. But if we just run them, nothing spikes out.
Any ideas?
My analysis of the issue goes like this..
First when DTU's are maxed out and if a query fails due to that,you will not get time out..Below is the error message you will get..
Resource ID: %d. The %s limit for the database is %d and has been reached. For more information
You can try testing that by opening multiple resource intensive queries
Secondly when you get time out's as indicated in your question,this is mostly due to query waiting for resources like say some database IO,memory..
we faced similar time out's ,but most of them are fixed by updating stats and rebuilding indexes,rest of them we optimized

SQL Server Geography Query - only slow on remote server

I'm running the following query which takes around 1 whole second to execute against 25k records
DECLARE #p GEOGRAPHY = GEOGRAPHY::Point('54.8175053','-2.03567480000003',4326)
SELECT *
FROM mytable
WHERE geoData.STDistance(#p) < 10000
On my remote server, this takes 6-9 seconds.
My I/O speed is faster than my computer, also no resources are being maxed and this is the only query running.
I'm using SQL Server 2008 R2 on both machines.
Could this be a configuration issue? I've noticed that re-running the query doesn't seem to cache anything (takes the exact same amount of time)
Thanks

SQL Server Agent Jobs Crashing

Running a Windows 2003 with SQL Server 2005 on, with around ~85-90 jobs which run once per hour (at different times), generating new sitemaps for each website hosted on the server, along with un-publishing pages.
The issue which I'm having with the server is that, the server seems to be running in three stages, the jobs run between 8am - 6pm each day, and the server is restarted around 2-3am every morning.
Once the jobs start in the morning, they will run successfully for around 90 minutes (9.30am), taking around 3-5 seconds to complete the job.
After 9.30, the jobs will start correctly, then, get stuck on executing (using 100% CPU).
If I manually stop the job, the server goes back to normal, but then the jobs will fail to execute at all, throwing the error below. (They were changed to run every 60 minutes, not every 15 a few months ago, but the names were never changed)
Step ID 1
Server [Server Name]
Job Name Execute Replicate File For [website] web
Step Name Vbscript for Replicate File every 15Minutes
Duration 00:00:00
Sql Severity 0
Sql Message ID 0
Operator Emailed
Operator Net sent
Operator Paged
Retries Attempted 0
Message
Executed as user: [Domain]\[User]. The step did not generate any output.
The step failed.
Information about the script that is running: It is a VBScript
Dim IEObj
Set IEObj=CreateObject("InternetExplorer.Application")
IEObj.Navigate "[weblink]/ReplicateFile.asp"
IEObj.visible=false
do Until IEObj.ReadyState=4
loop
IEObj.quit
Set IEObj=Nothing
#mellamokb - The script is down in the general settings as an ActiveX Script, not a T-SQL one, so I am unable to specify an output file for the errors.
Note: I didn't setup anything on this server or the CMS which it is replicating, and my knowledge of databases is fairly low.
My guess is that the page you are displaying in the browser, [weblink]/ReplicateFile.asp, is erroring out on at least one of sessions.
The code
do Until IEObj.ReadyState=4
loop
will cause significant CPU usage while it is running. And, more importantly, if the browser never gets to ReadyState 4, this code will continue to run forever. Have two of three of these stuck, and you will see 100% CPU usage on your server.

Suspended status in SQL Activity Monitor

What would cause a query being done in Management Studio to get suspended?
I perform a simple select top 60000 from a table (which has 11 million rows) and the results come back within a sec or two.
I change the query to top 70000 and the results take up to 40 min.
From doing a bit of searching on another but related issue I came across someone using DBCC FREEPROCCACHE to fix it.
I run DBCC FREEPROCCACHE and then redo the query for 70000 and it seemmed to work.
However, the issue still occurs with a different query.
I increase to say 90000 or if I try to open the table using [Right->Open Table], it pulls about 8000 records and stops.
Checking the activity log for when I do the Open Table shows the session has been suspended with a wait type of "Async_Network_IO". For the session running the select of 90000 the status is "Sleeping", this is the same status for the above select 70000 query which did return but in 45min. It is strange to me that the status shows "Sleeping" and it does not appear to be changing to "Runable" (I have the activiy monitor refreshing ever 30sec).
Additional notes:
I am not running both the Open Table and select 90000 at the same time. All queries are done one at a time.
I am running 32bit SQL Server 2005 SP2 CU9. I tried upgrading to SP3 but ran into install failurs. The issues was occuring prior to me trying this upgrade.
Server setup is an Active/Active cluster the issue occurs on either node, and the other instance does not have this issue.
I have ~20 other database on this same server instance but only this one DB is seeing the issue.
This database gets fairly large. It is currently at 76756.19MB. Data file is 11,513MB.
I am logged in locally on the Server box using Remote Desktop.
The wait type "Async_Network_IO" means that its waiting for the client to retrieve the result set as SQL Server's network buffer is full. Why your client isn't picking up the data in a timely manner I can't say.
The other case it can happen is with linked servers when SQL Server is querying a remote table, in this case SQL Server is waiting for the remote server to respond.
Something worth looking at is virus scanners, if they are monitoring network connections sometimes they can get lagged, its often apparent by them hogging all the CPU.
Suspended means it is waiting on a resource and will resume when it gets its resource. Judging from the sizes you are pulling back, it seems you are in an OLAP type of query.
Try the following things:
Use NOLOCK or set the TRANSACTION ISOLATION LEVEL at the top of the query
Check your execution plan and tune the query to be more efficient