Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Service Broker Expand / Collapse
Author
Message
Posted Saturday, October 20, 2012 11:41 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 24, 2013 12:02 PM
Points: 3, Visits: 17
In our environments, I have identified a problem with Service Broker and performance. We have a rows north of 50 million in sys.conversation_endpoints with DISCONNECTED_INBOUND.

We are dealing with the why's of this problem, but in terms of getting these rows removed is another problem altogether.

I have seen several theories on how to get this cleaned up. But most of them deal with a SELECT... CURSOR, and that is generally not good for speed and performance.

This one never actually ran (tempdb and page space problems)
DECLARE @handle UNIQUEIDENTIFIER

DECLARE conv_cur CURSOR FAST_FORWARD FOR SELECT CONVERSATION_HANDLE FROM SYS.CONVERSATION_ENDPOINTS (nolock) WHERE state_desc = 'DISCONNECTED_INBOUND'

OPEN conv_cur;

FETCH NEXT FROM conv_cur INTO @handle;

WHILE @@fetch_status = 0
BEGIN
END CONVERSATION @handle WITH CLEANUP
FETCH NEXT FROM conv_cur INTO @handle;
END

CLOSE conv_cur;
DEALLOCATE conv_cur;
GO

Currently I am using this:

DECLARE @t TABLE( AutoID INT IDENTITY, ConversationHandle UNIQUEIDENTIFIER)

-- insert the handles of all open conversations to the
-- memory table
INSERT INTO
@t (ConversationHandle)
SELECT top(1000000)
[conversation_handle]
FROM
sys.conversation_endpoints (nolock)
WHERE
state_desc = 'DISCONNECTED_INBOUND'


-- local variables
DECLARE @cnt INT, @max INT, @handle UNIQUEIDENTIFIER
SELECT @cnt = 1, @max = COUNT(*) FROM @t

-- run a loop for each row in the memory table
WHILE @cnt <= @max BEGIN
-- read the conversation_handle
SELECT
@handle = ConversationHandle
FROM @t WHERE AutoID = @cnt

-- end conversation
PRINT 'Closing conversation: ' + CAST(@handle AS VARCHAR(50))
END CONVERSATION @handle WITH CLEANUP

-- increment counter
SELECT @cnt = @cnt + 1
END

The problem with this one is I have to keep going back to rerun it.

Any way this can be enhanced so this whole process will go faster?

Thanks
Post #1375117
Posted Monday, October 22, 2012 1:26 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:21 AM
Points: 2,837, Visits: 3,954
Since you are dealing with good numbers of message to END the dialog.it wil take some time as every record will get processed with per ConversationHandle.Rerun will be there sonce it requires manual intervention.

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1375284
Posted Monday, October 22, 2012 8:29 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 24, 2013 12:02 PM
Points: 3, Visits: 17
I have come across other ideas, most of which require the DB being in single user mode

ALTER DATABASE TestDB
SET DISABLE_BROKER

ALTER DATABASE TestDB
SET ENABLE_BROKER

ALTER DATABASE TestDB WITH ERROR_BROKER_CONVERSATIONS

ALTER DATABASE TestDB
SET NEW_BROKER
WITH ROLLBACK IMMEDIATE

I don't know if the top two would remove messages, but perhaps the next two would. What would be the fallout or problem with executing the bottom two?
Post #1375457
Posted Saturday, October 27, 2012 8:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 24, 2013 12:02 PM
Points: 3, Visits: 17
This took only 10 seconds. So this will be used to remove the old entries, but I will schedule a maintenance job to END CONVERSATION any extra entries that continue to build up.

ALTER DATABASE SET SINGLE_USER WITH ROLLBACK IMMEDIATE 
GO
ALTER DATABASE TestDB SET NEW_BROKER
GO
ALTER DATABASE SET MULTI_USER
GO

Post #1377954
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse