473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cache HIT ratio problem

Hello

I am tring to figure out why our SQL server is a bit sluggish from
time to time.

It is running a dual XEON, with 2.5 GB RAM, and a fast SCSI I/O sub
system setup as follows.

OS, mirrored 2 drives
SQL DATA 16 HDD RAID 10
SQL LOG 4 HDD RAID 10
SQL tempdb 4 HDD RAID 10

OS = win 2003
SQL = sql2000 standard edition

dbcc showcontig shows me nothing special, it looks ok

I launch performacne monitor and add SQL server cache manager: hit
ratio

and it is constantly at 7% and never changes up or down, it is just
constant.

Can this be correct? and if so it sounds rather bad, we have a
handfull of large tables that are heavily used and enough RAM to hold
them all in RAM so I really do not understand why the cache hit ratio
is not higher.

Any hints would be great

rgds

Matt
Jul 23 '05 #1
9 8813
It's not impossible - the Cache Manager cache hit ratio is the number
of hits on a cached query plan, not on a cached data page. If you want
to see the cached data page ratio, you need to look under Buffer
Manager - that should be as close to 100% as possible.

Still, 7% does sound rather low, unless users are executing very
different queries every time, so that a cached plan can't be reused.
You might want to use Profiler to trace activity on the server during a
sluggish period, and see exactly what is running slowly.

Simon

Jul 23 '05 #2
"Simon Hayes" <sq*@hayes.ch> wrote in message news:<11**********************@f14g2000cwb.googleg roups.com>...
Still, 7% does sound rather low, unless users are executing very
different queries every time, so that a cached plan can't be reused.
You might want to use Profiler to trace activity on the server during a
sluggish period, and see exactly what is running slowly.


ok thanks a lot for the insight, it turns out the buffer hits are very
high indeed I was looking at the wrong counter.

I also used profiler and found the code causing my problems, but I
really do not know how to write it more efficiantly, it does not use
cursors, it does not use temp tables.

any hints would be much apprecaited as to how I can speed this query
up.

CREATE procedure q_spr_ordvalmonitor

AS

declare @maxpossible money,
@moneysofar money,
@moneysofar2 money

select @maxpossible =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst < 50 and
orp.ftgnr <> '11000'

select @moneysofar =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst = 50 and
orp.ftgnr <> '11000'

select @moneysofar2 = sum(ft.faktradsumma)
from ft
where ft.faktdat = convert(varchar(8), getdate(), 112) and
ft.kundkategorikod <> 17

if @moneysofar IS NULL
set @moneysofar = 0

if @moneysofar2 IS NULL
set @moneysofar2 = 0

select convert(numeric, @maxpossible) AS 'moneyremaining',
(convert(numeric, @moneysofar) + convert(numeric, @moneysofar2)) AS
'moneysofar'

rgds

It is used in some PHP code I wrote to display our current order
values.
Jul 23 '05 #3
Hi

To improve cache hits try starting with using qualified names. Adding owner
prefixes should help

http://msdn.microsoft.com/library/de...ar_sa_4azp.asp

You may also want to look at:
http://support.microsoft.com/default...b;en-us;325119

John

"Matt" <ma**@fruitsalad.org> wrote in message
news:b6**************************@posting.google.c om...
"Simon Hayes" <sq*@hayes.ch> wrote in message
news:<11**********************@f14g2000cwb.googleg roups.com>...
Still, 7% does sound rather low, unless users are executing very
different queries every time, so that a cached plan can't be reused.
You might want to use Profiler to trace activity on the server during a
sluggish period, and see exactly what is running slowly.


ok thanks a lot for the insight, it turns out the buffer hits are very
high indeed I was looking at the wrong counter.

I also used profiler and found the code causing my problems, but I
really do not know how to write it more efficiantly, it does not use
cursors, it does not use temp tables.

any hints would be much apprecaited as to how I can speed this query
up.

CREATE procedure q_spr_ordvalmonitor

AS

declare @maxpossible money,
@moneysofar money,
@moneysofar2 money

select @maxpossible =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst < 50 and
orp.ftgnr <> '11000'

select @moneysofar =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst = 50 and
orp.ftgnr <> '11000'

select @moneysofar2 = sum(ft.faktradsumma)
from ft
where ft.faktdat = convert(varchar(8), getdate(), 112) and
ft.kundkategorikod <> 17

if @moneysofar IS NULL
set @moneysofar = 0

if @moneysofar2 IS NULL
set @moneysofar2 = 0

select convert(numeric, @maxpossible) AS 'moneyremaining',
(convert(numeric, @moneysofar) + convert(numeric, @moneysofar2)) AS
'moneysofar'

rgds

It is used in some PHP code I wrote to display our current order
values.

Jul 23 '05 #4
"John Bell" <jb************@hotmail.com> wrote in message news:<42***********************@news.zen.co.uk>...
Hi

To improve cache hits try starting with using qualified names. Adding owner
prefixes should help

http://msdn.microsoft.com/library/de...ar_sa_4azp.asp

You may also want to look at:
http://support.microsoft.com/default...b;en-us;325119

I read it and I added qualified names, once I got the correct counter
added, I am running an avg of 90% or more cache hits, the issue at
hand is that the below query seems to kill my I/O subsystem, as soon
as it runs my avg disk queue hits 100% and the entire SQL server gets
sluggish and slow for the duration of this query which lasts for about
20-30 seconds.

It seems to me like a fairly simple query and I just dont get why it
is so hard on the server, I have checked for table scans, indexes
troubles but it all seems ok, there are basically no table scans so I
am assuming the indexer are working as planned, but still the I/O goes
through the roof on this query.


CREATE procedure q_spr_ordvalmonitor

AS

declare @maxpossible money,
@moneysofar money,
@moneysofar2 money

select @maxpossible =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst < 50 and
orp.ftgnr <> '11000'

select @moneysofar =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst = 50 and
orp.ftgnr <> '11000'

select @moneysofar2 = sum(ft.faktradsumma)
from ft
where ft.faktdat = convert(varchar(8), getdate(), 112) and
ft.kundkategorikod <> 17

if @moneysofar IS NULL
set @moneysofar = 0

if @moneysofar2 IS NULL
set @moneysofar2 = 0

select convert(numeric, @maxpossible) AS 'moneyremaining',
(convert(numeric, @moneysofar) + convert(numeric, @moneysofar2)) AS
'moneysofar'

rgds

It is used in some PHP code I wrote to display our current order
values.

Jul 23 '05 #5
Hi Matt

Look at profiler and see where the high reads/durations occur. You may
me missing suitable indexing.

Also

convert(varchar(8), ,..112) this can be char(8), but if you can change
(orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112))

to something like
orp.ordberlevdat > @date1
and orp.ordberlevdat < @date2

then you may improve the performance.

You may want to also try:

select @moneysofar =
sum( CASE WHEN orp.ordradst = 50 THEN
(orp.ordantal*orp.vb_pris)**(100-orp.rabatt1)/100 END)
@moneysofar =
sum( CASE WHEN orp.ordradst < 50 THEN
(orp.ordantal*orp.vb_pris)**(100-orp.rabatt1)/100) END)
from orp
WHERE orp.ordradst <= 50

John

Jul 23 '05 #6
Matt (ma**@fruitsalad.org) writes:
select @maxpossible =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst < 50 and
orp.ftgnr <> '11000'

select @moneysofar =
sum((orp.ordantal*orp.vb_pris)*(100-orp.rabatt1)/100)
from orp
where (orp.ordberlevdat = convert(varchar(8), getdate(), 112) or
orp.ordberlevdat = convert(varchar(8), dateadd(day, -1, getdate()),
112)) and
orp.ordradst = 50 and
orp.ftgnr <> '11000'


I don't really see why this query would take so much power from
the machine, but then again I don't know how many rows you have
in your tables. Anyway, if the problem is with the access to orp,
then at least this should give you a 50% reduction.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7
"John Bell" <jb************@hotmail.com> wrote in message news:<11**********************@l41g2000cwc.googleg roups.com>...
Hi Matt

Look at profiler and see where the high reads/durations occur. You may
me missing suitable indexing.

Also

convert(varchar(8), ,..112) this can be char(8), but if you can change
(orp.ordberlevdat =3D convert(varchar(8), getdate(), 112) or
orp.ordberlevdat =3D convert(varchar(8), dateadd(day, -1, getdate()),
112))

to something like
orp.ordberlevdat > @date1
and orp.ordberlevdat < @date2

then you may improve the performance.

You may want to also try:

select @moneysofar =3D
sum( CASE WHEN orp.ordradst =3D 50 THEN
(orp.ordantal*orp.vb_pris)=AD*(100-orp.rabatt1)/100 END)
@moneysofar =3D
sum( CASE WHEN orp.ordradst < 50 THEN
(orp.ordantal*orp.vb_pris)=AD*(100-orp.rabatt1)/100) END)
from orp=20
WHERE


orp.ordradst <=3D 50

cooool that made a huge difference, thanks a lot, the query now runs
in sub 4 seconds.

rgds

Matt
Jul 23 '05 #8
Hi Matt

Did you do the date thing? That should also help.

Also remove the two if statements and do
select convert(numeric, ISNULL(@maxpossible,0)) AS 'moneyremaining',
(convert(numeric, ISNULL(@moneysofar)) + convert(numeric,
ISNULL(@moneysofar2))) AS
'moneysofar'

Look at changing your money data types to a decimial with fixed
precision.

John

Jul 23 '05 #9
Hi

Another thing to help would be to pass the values as output parameters!

John

John Bell wrote:
Hi Matt

Did you do the date thing? That should also help.

Also remove the two if statements and do
select convert(numeric, ISNULL(@maxpossible,0)) AS 'moneyremaining', (convert(numeric, ISNULL(@moneysofar)) + convert(numeric,
ISNULL(@moneysofar2))) AS
'moneysofar'

Look at changing your money data types to a decimial with fixed
precision.

John


Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lasmith3 | last post by:
This issue just happen recently. The buffer cache ratio went from > 90% to 50% and has slowly been climbing back up over 8 hours or so. Its currently @ 76%. Is this something I should take action...
4
by: xixi | last post by:
the formula for package cache hit ratio is 1 - (package cache inserts/package cache lookups), what the result would be a effective ratio? currently we have cache inserts=25, cache lookups=35, so...
1
by: Jim | last post by:
Hi, I have a few questions regarding the cache object: Does the cache object exist through postbacks? The cache object only exists for the current request, right? Is there a way to cache...
0
by: shterke | last post by:
Good day, I've been monitoring a DB2 system and noticed a low package cache hit ratio, I calculated it based on the formula in the db2 information center: ...
1
by: Marek Wierzbicki | last post by:
Hi I have trouble with MSSQL2000 SP4 (without any hotfixes). During last two weeks it start works anormally. After last optimalization (about few months ago) it works good (fast, without...
5
by: J055 | last post by:
Hi The following code works on my develeopment machine using the VS web server. When I run the application on 2 other Windows 2003/IIS 6 servers no caching seems to take place at all. Can...
0
by: Hypnotik | last post by:
My program is to simulate cache memory. I read in the info from 2 external files, 1) access 2) data in memory. When I read the information in I display the info...and it is all correct. However...
1
by: Ramchandra | last post by:
Hi , i am facing problem in package cache hit ratio its between 47-45% which is very less:- here are my configuration related to package cache:- Catalog cache size (4KB) ...
0
by: lekhrajm | last post by:
Hi, I want to flush Dynamic Sql CACHE completely in db2 9.1.2 I used command "db2 FLUSH PACKAGE CACHE DYNAMIC". But it lefts some queries in cache. These are fixed queries. It creats problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.