October 20, 2012 at 11:41 am
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-2 INT, @handle UNIQUEIDENTIFIER
SELECT @cnt = 1, @max-2 = COUNT(*) FROM @t
-- run a loop for each row in the memory table
WHILE @cnt <= @max-2 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
October 22, 2012 at 1:26 am
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;-)
October 22, 2012 at 8:29 am
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?
October 27, 2012 at 8:57 am
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply