Showing posts with label configuration. Show all posts
Showing posts with label configuration. Show all posts

Monday, March 12, 2012

Inconsistent SP performance on different Servers

One of my developers recently installed a backup of the production database onto his test site. His test server has the same configuration as the production server.

One of the Stored Procedures that is called takes 1:45 to run on his machine, but only 2 seconds on the production server. This same SP takes only 2 seconds on my development database.

The SP is called iteratively, up to 10 times... to run against 10 separate fields. Depending on a value for a parameter called @.CriteriaClassID, depends on which portion of the SP runs.

The significant difference in processing time in itself is baffling (since the servers are same specs / configuration, as far as I can tell, and the data is identical, since he has a backup of the most recent production data).

But more baffling: if, in his data, I switch the values from field 1 to field 2, and vice versa, his results take 2 seconds (switching the values in field 1 to field 2 switches the value in @.CriteriaClassID which is passed through to this SP).

It's exactly the same SP; the only difference is that field 1 is processed first, field 2 second, field 3 third etc. On the production site and my development site, it doesn't make a difference in the order they are processed. On his machine it does.

Any ideas? I though perhaps his Indexes were corrupted in the rebuild, but we ran a SQL Server maintenance schedule to clean it up, and no improvement.

This is the SP, if it is of any help:

CREATE procedure [dbo].[st_pull_model_data] @.ModelID as integer, @.CriteriaID as integer
as

declare @.ClientID as integer, @.CriteriaClassId as char(1)

/*Procedure to pull data from org_model_data and postalcode_model_data for modeling and media analysis */
/*Need to have table #temp_data created outside of SP with fields org_id and zip_code */
/*This procedure is used by SP st_model_data */

If @.CriteriaID is not null
begin

set @.CriteriaClassId = (Select model_criteria_type from model_criteria where model_criteria_id = @.CriteriaID)
if @.CriteriaClassID = 'G' -- changes client_id from specific to general, if General is required.
begin
set @.ClientID = 0
end
else
begin
set @.ClientID = (Select client_id from model where model_id = @.ModelID)
end

If @.CriteriaClassId in ('G','P')
Begin
update #temp_data
set data1 = postal_criteria_value
from #temp_data t
left outer join
(select postalcode, postal_criteria_value
from postalcode_model_data pmd
join model_org_trade_area mota on mota.zip_code = pmd.postalcode
join model_org mo on mo.model_org_id = mota.model_org_id
where model_criteria_id = @.CriteriaID
and client_id = @.ClientID
and mo.model_id = @.ModelID) as PMD
on PMD.postalcode = t.zip_code
end
else
Begin
update #temp_data
set data1 = org_criteria_value
from #temp_data t
left outer join
(select distinct postalcode, org_criteria_value, omd.org_id
from org_model_data omd
join org o on o.org_id = omd.org_id
join model_org_trade_area mota on mota.zip_code = omd.postalcode
join model_org mo on mo.model_org_id = mota.model_org_id and mo.org_id = o.org_id
where model_criteria_id = @.CriteriaID and o.client_id = @.ClientID and mo.model_id = @.ModelID) as OMD
on OMD.postalcode = t.zip_code and omd.org_id = t.org_id
end
endJust a thought on something to try...

Declare two local variables that are similar to the two passed in parameters, copy the parameters to these local variables at the top of your sporc and then use the local variables only within the code.

If this has the effect of solving your issue, you have a "parameter sniffing" issue.|||One other thought, is his tempdb on the same physical disk as the database data files? It won't explain the whole performance problem, but it will explain a part.|||Chopin,

Thanks a ton. The inclusion of the two local variables (copying over the SP variables) solved the problem for performance.

Another lesson learned.|||In that case does that mean backup restore do not restore query plans for the stored proc in the database? Any idea?|||NO ... backup does not save the procedure cache.

Friday, February 24, 2012

Inactive Publisher???

I set up a Tranactional replication configuration and created a publication
in SQL2005. When I set up the subscriber the wizard stated all succeeded.
However, when I went to the Replication Monitor there was a error for the
publisher. I went to the history for the agent and it stated the following:
2007-02-09 17:56:51.44 Connecting to Distributor 'U1ST081SORTS2'
2007-02-09 17:56:51.57 The replication agent had encountered an exception.
2007-02-09 17:56:51.57 Source: Replication
2007-02-09 17:56:51.57 Exception Type:
Microsoft.SqlServer.Replication.ReplicationAgentEx ception
2007-02-09 17:56:51.57 Exception Message: The snapshot could not be
generated because the publisher is inactive.
2007-02-09 17:56:51.57 Message Code: 54057
Now, this is not only new to me but also to BOL because I couldn't find
anything about inactive "publishers", only subscribers. Also the Message
code didn't provide any answers. I've found places to change subscriber
inactivity timeouts but nothing for publishers.
Any ideas? I'm used to setting up replication in SQL2K and haven't had this
many problems before. Any significant changes in how to set up replication
with 2005?
Roger.
How did you create your publication?
By chance did you did it like this?
sp_addpublication 'mypublication'?
You need to specify the @.status='active' parameter.
Do a sp_helppublication and note the status field is it 0 or 1. 1 means
active.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Roger Denison" <RogerDenison@.discussions.microsoft.com> wrote in message
news:0EF738C9-9EE5-43C9-B19C-117280FAA1AB@.microsoft.com...
>I set up a Tranactional replication configuration and created a publication
> in SQL2005. When I set up the subscriber the wizard stated all succeeded.
> However, when I went to the Replication Monitor there was a error for the
> publisher. I went to the history for the agent and it stated the
> following:
> 2007-02-09 17:56:51.44 Connecting to Distributor 'U1ST081SORTS2'
> 2007-02-09 17:56:51.57 The replication agent had encountered an exception.
> 2007-02-09 17:56:51.57 Source: Replication
> 2007-02-09 17:56:51.57 Exception Type:
> Microsoft.SqlServer.Replication.ReplicationAgentEx ception
> 2007-02-09 17:56:51.57 Exception Message: The snapshot could not be
> generated because the publisher is inactive.
> 2007-02-09 17:56:51.57 Message Code: 54057
> Now, this is not only new to me but also to BOL because I couldn't find
> anything about inactive "publishers", only subscribers. Also the Message
> code didn't provide any answers. I've found places to change subscriber
> inactivity timeouts but nothing for publishers.
> Any ideas? I'm used to setting up replication in SQL2K and haven't had
> this
> many problems before. Any significant changes in how to set up
> replication
> with 2005?
> --
> Roger.
|||Hi Roger,
You can set the publisher to active by running sp_changedistpublisher
@.publisher = <your publisher name>, @.property = 'active', @.value = 'true' at
the distributor, although this happens often enough
([url]http://groups.google.com/group/microsoft.public.sqlserver.replication/browse_frm/thread/cb0ab8eb51efbdc0/20d2368928450759?lnk=gst&rnum=41#20d2368928450759[ /url])
that I am a bit worried about what kind of subtle problems we missed during
replication setup through SSMS. Are you having a SQL2000 publisher by any
chance?
-Raymond
"Roger Denison" <RogerDenison@.discussions.microsoft.com> wrote in message
news:0EF738C9-9EE5-43C9-B19C-117280FAA1AB@.microsoft.com...
>I set up a Tranactional replication configuration and created a publication
> in SQL2005. When I set up the subscriber the wizard stated all succeeded.
> However, when I went to the Replication Monitor there was a error for the
> publisher. I went to the history for the agent and it stated the
> following:
> 2007-02-09 17:56:51.44 Connecting to Distributor 'U1ST081SORTS2'
> 2007-02-09 17:56:51.57 The replication agent had encountered an exception.
> 2007-02-09 17:56:51.57 Source: Replication
> 2007-02-09 17:56:51.57 Exception Type:
> Microsoft.SqlServer.Replication.ReplicationAgentEx ception
> 2007-02-09 17:56:51.57 Exception Message: The snapshot could not be
> generated because the publisher is inactive.
> 2007-02-09 17:56:51.57 Message Code: 54057
> Now, this is not only new to me but also to BOL because I couldn't find
> anything about inactive "publishers", only subscribers. Also the Message
> code didn't provide any answers. I've found places to change subscriber
> inactivity timeouts but nothing for publishers.
> Any ideas? I'm used to setting up replication in SQL2K and haven't had
> this
> many problems before. Any significant changes in how to set up
> replication
> with 2005?
> --
> Roger.
|||Raymond/Hillary,
I used the wizard that came with SQL2005 to set up the publisher and
subscription. I used the sp that Hillary gave me determine the status.
Use Distribution
Execute sp_helppublication
Go
But all I saw was a successful completion. No results. Unlike 2000, which
provided results, I'm still getting used to how 2005 works.
Likewise, I ran sp_changedistpublisher as Raymond specified but it couldn't
find my publisher 'Autosort081 XRep'. It said to make sure it was registered
in sysservers in the distributor. I can't find that table (or anything
resembling) and even if I did I can't open it in Dist or Master. Just
another thing I don't like about 2005.
I do have publishers in 2000 but they only publish to other 2000 servers,
not 2005.
Roger.
"Raymond Mak [MSFT]" wrote:

> Hi Roger,
> You can set the publisher to active by running sp_changedistpublisher
> @.publisher = <your publisher name>, @.property = 'active', @.value = 'true' at
> the distributor, although this happens often enough
> ([url]http://groups.google.com/group/microsoft.public.sqlserver.replication/browse_frm/thread/cb0ab8eb51efbdc0/20d2368928450759?lnk=gst&rnum=41#20d2368928450759[ /url])
> that I am a bit worried about what kind of subtle problems we missed during
> replication setup through SSMS. Are you having a SQL2000 publisher by any
> chance?
> -Raymond
> "Roger Denison" <RogerDenison@.discussions.microsoft.com> wrote in message
> news:0EF738C9-9EE5-43C9-B19C-117280FAA1AB@.microsoft.com...
>
>
|||Roger, looks like your replication setup may be in a pretty bad state
(specifically the distributor doesn't seem to know anything about your
publisher). You may need to tear down all replication meta-data at your
publisher (likely by using @.ignore_distributor = 1 in various replication sp
calls). But before doing that, can you tell me how you upgrade the
distributor in the first place? You may also want to check the sys.servers
table in the master database and the MSdistpublishers table in msdb on your
distributor and see if there are any signs that the distributor actually
knows about your publisher at this point.
-Raymond
"Roger Denison" <RogerDenison@.discussions.microsoft.com> wrote in message
news:FF68B0C8-7B2B-4E70-BAD0-197FC3CDC91C@.microsoft.com...[vbcol=seagreen]
> Raymond/Hillary,
> I used the wizard that came with SQL2005 to set up the publisher and
> subscription. I used the sp that Hillary gave me determine the status.
> Use Distribution
> Execute sp_helppublication
> Go
> But all I saw was a successful completion. No results. Unlike 2000,
> which
> provided results, I'm still getting used to how 2005 works.
> Likewise, I ran sp_changedistpublisher as Raymond specified but it
> couldn't
> find my publisher 'Autosort081 XRep'. It said to make sure it was
> registered
> in sysservers in the distributor. I can't find that table (or anything
> resembling) and even if I did I can't open it in Dist or Master. Just
> another thing I don't like about 2005.
>
> I do have publishers in 2000 but they only publish to other 2000 servers,
> not 2005.
> --
> Roger.
>
> "Raymond Mak [MSFT]" wrote:
|||Thanks for your input, Raymond. You think things are messed up, I have two
publications that I can't delete becasue they "don't exist". And I can't
drop a couple of tables because they are used for replication by the two
publishers that don't exist. But that's another issue. This has been a lot
of fun trying to work in 2005.
For starters, I haven't upgraded anything from 2000 to 2005. With my latest
project, my IT guy purchased 2005 instead of 2000. I was able to import data
from one of my other servers so i wasn't starting from scratch. But there
was no replication associated with the tables at that point.
I then imported data from the publisher to the subscriber so that the schema
would already be present on the subscriber.
So I set up my subscriber as the distributor using the wizard. I then
created the publication on the publisher server. As you probably guessed
there are 2 servers in this scenario. From the publication, I launch the New
Subscriber... wizard to create the subscription. I request the publication
to start the snapshot and start the log reader (this is a trans rep). The
wizard says that everything completed successfully but RepMon shows errors.
Now, you ask me to look in some tables in Master or Distribution but I
cannot look at the data. Even though I am logged on as SA I cannot open any
of those ("open table" is grayed out) How do I go about getting access to
the system tables?
Roger.
"Raymond Mak [MSFT]" wrote:

> Roger, looks like your replication setup may be in a pretty bad state
> (specifically the distributor doesn't seem to know anything about your
> publisher). You may need to tear down all replication meta-data at your
> publisher (likely by using @.ignore_distributor = 1 in various replication sp
> calls). But before doing that, can you tell me how you upgrade the
> distributor in the first place? You may also want to check the sys.servers
> table in the master database and the MSdistpublishers table in msdb on your
> distributor and see if there are any signs that the distributor actually
> knows about your publisher at this point.
> -Raymond
> "Roger Denison" <RogerDenison@.discussions.microsoft.com> wrote in message
> news:FF68B0C8-7B2B-4E70-BAD0-197FC3CDC91C@.microsoft.com...
>
>