SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Service Broker


Service Broker

Author
Message
jchristl
jchristl
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
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
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13280 Visits: 4077
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;-)
jchristl
jchristl
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
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?
jchristl
jchristl
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search