A related question/issue re: statement cache usage ...
Could you post a copy of the Statement Cache area from a sp_sysmon session during a period when you had statement cache
enabled?
I'm curious to see if those cached statements are actually being used (ie, is Statements Found in Cache > 0? is
Statements Dropped/Not Found > 0?).
----------------
With ASE 12.5.x I found that the statement cache worked great when I had a large volume of the same *EXACT* query coming
into the dataserver ...
select * from sysobjects where id = 8
select * from sysobjects where id = 8
select * from sysobjects where id = 8
... but statement cache was a waste of resources (memory, hashing, recycling statement cache entries) when the queries
were similar but not *EXACT* ...
select * from sysobjects where id = 7
select * from sysobjects where id = 8
select * from sysobjects where id = 9
When the second set of queries were hashed, 3 different hash keys would be generated and thus require 3 different
queries to be optimized and placed into the statement cache. None of the query plans were re-used from statement cache.
At a couple clients the vast majority of the queries (primary and replicate databases) were more like the second set of
queries, so we received no benefit from having statement cache enabled.
In fact we actually saw some degradation in performance due to all of the churning in the statement cache (think one big
FIFO/queue with *all* queries being stuffed in the front and then ignored until they were pushed out the back side).
Performance degradation took the form of increased cpu utilization (think: hash a query, search for match in statement
cache but not find anything, *optimize query*, push on statement cache, remove oldest query from statement cache, etc).
Notice that *all* queries were having to be compiled anyway (ie, no benefit from (re)using pre-compiled plans from
statement cache).
So while your queries will certainly be compiled and placed in the statement cache I'd be more intested in finding out
if those entries (in statement cache) are actually being (re)used. If not, you're wasting memory and cpu cycles.
----------------
And for completeness sake ...
With ASE 15.0.1 a new configuration parameter was provided: 'enable literal autoparam'. (see ASE 15.0.1 What's New manual)
This parameter, when used in conjunction with 'statement cache size' > 0, allows the dataserver to view similar queries
(eg, second batch of queries - above) as being the same.
In a nutshell the parser replaces all static values with temporary variables (eg, @@@V0_INT, @@@V1_VARCHAR,
@@@V2_DATETIME). The second set of queries would thus be converted into:
select * from sysobjects where id = @@@V0_INT
select * from sysobjects where id = @@@VO_INT
select * from sysobjects where id = @@@V0_INT
At this point the queries are then hashed, and since the queries are now *EXACTLY* alike we find matches in statement
cache; this in turn means we can benefit from (re)using pre-compiled query plans from statement cache.
At a couple of my clients the use of 'enable literal autoparam' and 'statement cache size' has come in real handy in
replicate databases. With ASE 15.x the optimizer has to do a lot more work (ie, query compilation takes longer), so DSI
connections tend to take longer to process queries. (In one case replication fell behind during the first night's batch
processing and never caught up due to the slow(er) optimizer in the replicate database.) Once we configured 'enable
literal autoparam' and 'statement cache size' we found that replication returned to pre-ASE 15 levels of performance
(due to the heavy re-use statement cache query plans in the replicate database).
NOTE: RepServer 15.0.1 has a new feature (Dynamic SQL, aka Prepared Statements) which should provide a similiar benefit
to using 'enable literal autoparam' and 'statement cache size' in a replicate ASE 15.x dataserver. This feature
actually offloads some of the processing (eg, statement cache management) from the RDS, though you'll also see an
increase in procedure cache usage (prepared statements == dynamic stored procs == lightweight stored procs) in the RDS.
And yeah, there are some tradeoffs to using statement cache, eg, they suffer from the same problems as a stored proc
that can be compiled in one of several different ways depending on the value of input parameters.
While the following 2 queries may hash to the same key they may actually require a different query plan:
select * from sysobjects where id between 1 and 1 (use index on id ?)
select * from sysobjects where id between -2147000000 and 2147000000 (perform table scan ?)
The first query will be compiled and placed in statement cache with a query plan that is best for it. The second query
will be hashed and match the first query's plan from statement cache; this could lead to the second query performing
poorly (due to using the first query's plan) when it would probably perform more efficiently with a different query plan.
Similar issues arise if you switch the order of the 2 queries.
--------------------
Anyhoo, 'nuff of the tangents and rambling for now ...
Post by LinkRight, I did happen to read that but with increasing the size of the
'procedure cache' => the size I had configured for the 'statement cache', I
wasn't expecting to see the spike in 'procedure removals' from the sysmon
report unless it's very significant. I'm trying to use some of the other
counters to see if I need to increase the size of the procedure cache
altogether when I add a statement cache. Maybe it's the replication
statements/volume getting turned into LWP's that is pushing the 'procedure
cache' beyonds it's typical limits with 'statement cache' enabled. If
that's the case, at this point, I have to wonder if turning off the
'statement cache' is the better option. Maybe this isn't meant for a
heavily replicated, reporting env.
Post by Mark KThe statements become lightweight procedures (LWPs). Perhaps the LWPs are
being removed and getting counted under Procedure Removals. I haven't
tested that theory, but just thought I'd suggest it for now.
Mark Kusma
Post by Mark KStatement Cache adds pages to the Procedure Cache, it does not take away
pages. Does your reporting server have stored procedures being executed, or
is everything just plain SQL?
Mark Kusma
Post by Sybase Replication ServerAll -
In reviewing my sysmons for a reporting dataserver, I found that my
'Statements not cached' were non-zero with my 'statement cache size'
configured at '0'. So, for testing, I increased that configuration to
'100' MB to see what effects this would have in sysmon.
Before starting my tests, I also looked at 'Procedure Removals' which
have been consistently ~0 for months. Immediately upon testing and
my subsequent sysmons, my 'Statements not Cached' drop to 0, but my
'Procedure Removal' jumped anywhere from 12-49 for each 5 minute
sysmon interval. I then did some testing to try and get my 'Procedure
Removal' back down to ~0 by (1) increasing my Procedure Cache size by
100 Mb to offset my 'Statement Cache' configuration, (2) dropping my
'Statement Cache Size' to 50 Mb, 10Mb and 1 Mb (all the while still
seeing 0 for my Statements not Cached') but yet my 'Procedure Removal'
is never dropping to/near pre-test levels, and actually fluctuating
quite a bit for my sysmon intervals.
My question is if (1) this is expected and that the decrease in
'Statement Cache' size while dynamic, really won't happen until reboot
and (2) if by turning on 'Statement Cache' I've turned a corner that I
can change until I turn off 'Statement Cache' and reboot to give back
all memory to the Procedure Cache. I may have over configured the
'Statement Cache' which is why I'm testing and running sysmon's to
find a good range. I'm going to be monitoring this over the next
few days to see if anything changes maybe with statements in cache
need to age out on their own and I'll slowly start seeing my
'Procedure Removal' drop as statements age out, although I've
increased my 'Procedure Cache' size by 1 Gb over and above what was
originally configured, which suprises me that I didn't immedately jump
back to 0 for removals.
Any thoughts/experience seen on this?
UPDATE: version 12.5.3/EBF 13057 ESD#5
I've reconfigured the 'Statement Cache' down to 0, which was reflected
in the sysmon, 'statements not in cache' went to non-zero, at which
point I re-configured my 'statement cache' to 10Mb and was able to get
it back to non-zero. But, my overall procedure cache size is much
larger than it was originally and I'm not seeing that come down to ~0
which is what it originally what is was for months leadiing up to my
testing. odd.
It's a combination of both, procedures and statements (this is
replicated environment). My belief is that these 'statements' are the
inserts/updates/deletes from the RS since we're not replicating
procs.
From my readings, I would not expect to see the 'procedure cache
behavior' because an adjustment was made to the 'procedure cache size'
to offset what I created for the 'statement cache'. The only way I
get my 'procedure removal' to drop to near 0 again is by turning of
'statement cache' completely.