Hi
I am sending messages to a remote server using SSB. The messages are sometimes generated at the rate of, say, 10 per second. For each message, my application creates a separate thread, and calls a sproc to send the message.
The sproc assembles a message and then finishes with this
declare @h uniqueidentifier
set @h = (select top 1 conversation_handle
from sys.conversation_endpoints ce
join sys.service_contracts sc
on sc.service_contract_id = ce.service_contract_id
where sc.name = 'MyContract')
IF @h IS null
BEGIN
BEGIN DIALOG CONVERSATION @h
FROM SERVICE MyService
TO SERVICE 'MyService'
ON CONTRACT MyContract
WITH ENCRYPTION=OFF
END
;SEND ON CONVERSATION @h
MESSAGE TYPE MyMessage
(@xmlmessage)
What I am finding is that the SEND takes a finite time to complete, and as each other thread tries to execute this statement it has to wait. The number of waiting threads increases until I get an avalanche effect, with more connections being opened to the database and eventually the connection pool is exhausted, and it all starts to unravel.
Although multiple threads are spawned to deal with the incoming messages, I want to send on a single conversation to maintain ordering, and to avoid the overhead of having to manage multiple conversations. I'm also conscious of the increased overhead at both ends of creating and tearing down conversations.
Firstly, can anyone confirm that what I am seeing is likely to be caused by the SEND statement locking the conversation handle, causing the following threads to wait?
But, perhaps more importantly, can anyone suggest a solution to this?
Thanks
Charles