|
|
|
Forum 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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
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---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Forum 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?
|
|
|
|
|
Forum 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
|
|
|
|