PC Review


Reply
Thread Tools Rate Thread

Can a web service be implemented as a multithreaded Singleton?

 
 
Thirsty Traveler
Guest
Posts: n/a
 
      26th Aug 2006
I have a need to implement a webservice where speed is of the essence. This
web service will process product orders in a B2B Extranet scenario where
SLA's are critical, as well as collect metrics on the duration of various
milestones through the application layers path that will be persisted to a
BizTalk 2006 BAM interface for QoS tracking and reporting. Orders not
meeting specified SLA agreements will be automatically cancelled and no
payment received, thus it is in our interest to reduce this as much as
possible.

Because the BAM API call is another path through the layers peripheral to
the order I would like to write the collected metrics to a global
synchronized Queue object and process it out of band via a worker thread
created when the Singleton is instantiated, thus allowing the primary
product order request to finish as quickly as possible. (The worker thread
will consume the Queue and persist the collected metrics, however speed is
not an issue here).

Question: Is this doable?


 
Reply With Quote
 
 
 
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      26th Aug 2006
Thirsty Traveler wrote:
> I have a need to implement a webservice where speed is of the
> essence. This web service will process product orders in a B2B
> Extranet scenario where SLA's are critical, as well as collect
> metrics on the duration of various milestones through the application
> layers path that will be persisted to a BizTalk 2006 BAM interface
> for QoS tracking and reporting. Orders not meeting specified SLA
> agreements will be automatically cancelled and no payment received,
> thus it is in our interest to reduce this as much as possible.
>
> Because the BAM API call is another path through the layers
> peripheral to the order I would like to write the collected metrics
> to a global synchronized Queue object and process it out of band via
> a worker thread created when the Singleton is instantiated, thus
> allowing the primary product order request to finish as quickly as
> possible. (The worker thread will consume the Queue and persist the
> collected metrics, however speed is not an issue here).
>
> Question: Is this doable?


Sure. Are there any particular parts that you're looking for help with?
There's good support in .NET for all of the primitive bits that you'd need
to build this.

Given the kind of application you're describing, I'd think you'd want to
write metrics to something like an MSMQ queue, not just a simple IPC queue,
since then you'd get fault tollerance, crash recovery, and so on "for free"
(of course, nothing's ever free). You could also use a SQL Server table, or
if you're using SQL Server 2005, you could use SQL Server notification
services (son of MSMQ) to queue the message to another process or thread.

-cd


 
Reply With Quote
 
Thirsty Traveler
Guest
Posts: n/a
 
      27th Aug 2006
"Carl Daniel [VC++ MVP]" <(E-Mail Removed)>
wrote in message news:%(E-Mail Removed)...
> Thirsty Traveler wrote:
>> I have a need to implement a webservice where speed is of the
>> essence. This web service will process product orders in a B2B
>> Extranet scenario where SLA's are critical, as well as collect
>> metrics on the duration of various milestones through the application
>> layers path that will be persisted to a BizTalk 2006 BAM interface
>> for QoS tracking and reporting. Orders not meeting specified SLA
>> agreements will be automatically cancelled and no payment received,
>> thus it is in our interest to reduce this as much as possible.
>>
>> Because the BAM API call is another path through the layers
>> peripheral to the order I would like to write the collected metrics
>> to a global synchronized Queue object and process it out of band via
>> a worker thread created when the Singleton is instantiated, thus
>> allowing the primary product order request to finish as quickly as
>> possible. (The worker thread will consume the Queue and persist the
>> collected metrics, however speed is not an issue here).
>>
>> Question: Is this doable?

>
> Sure. Are there any particular parts that you're looking for help with?
> There's good support in .NET for all of the primitive bits that you'd need
> to build this.
>
> Given the kind of application you're describing, I'd think you'd want to
> write metrics to something like an MSMQ queue, not just a simple IPC
> queue, since then you'd get fault tollerance, crash recovery, and so on
> "for free" (of course, nothing's ever free). You could also use a SQL
> Server table, or if you're using SQL Server 2005, you could use SQL Server
> notification services (son of MSMQ) to queue the message to another
> process or thread.
>
> -cd
>
>

I thought about using MSMQ. However I have no experience with it. Our web
service is in a DMZ while the business logic and data access layers are
behind the firewall in an internal network. Do you happen to know if this
will pose a problem with MSMQ?


 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      27th Aug 2006
Thirsty Traveler wrote:
> "Carl Daniel [VC++ MVP]"
> <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Thirsty Traveler wrote:
>>> I have a need to implement a webservice where speed is of the
>>> essence. This web service will process product orders in a B2B
>>> Extranet scenario where SLA's are critical, as well as collect
>>> metrics on the duration of various milestones through the
>>> application layers path that will be persisted to a BizTalk 2006
>>> BAM interface for QoS tracking and reporting. Orders not meeting
>>> specified SLA
>>> agreements will be automatically cancelled and no payment received,
>>> thus it is in our interest to reduce this as much as possible.
>>>
>>> Because the BAM API call is another path through the layers
>>> peripheral to the order I would like to write the collected metrics
>>> to a global synchronized Queue object and process it out of band via
>>> a worker thread created when the Singleton is instantiated, thus
>>> allowing the primary product order request to finish as quickly as
>>> possible. (The worker thread will consume the Queue and persist the
>>> collected metrics, however speed is not an issue here).
>>>
>>> Question: Is this doable?

>>
>> Sure. Are there any particular parts that you're looking for help
>> with? There's good support in .NET for all of the primitive bits
>> that you'd need to build this.
>>
>> Given the kind of application you're describing, I'd think you'd
>> want to write metrics to something like an MSMQ queue, not just a
>> simple IPC queue, since then you'd get fault tollerance, crash
>> recovery, and so on "for free" (of course, nothing's ever free). You
>> could also use a SQL Server table, or if you're using SQL Server
>> 2005, you could use SQL Server notification services (son of MSMQ)
>> to queue the message to another process or thread.
>>
>> -cd
>>
>>

> I thought about using MSMQ. However I have no experience with it. Our
> web service is in a DMZ while the business logic and data access
> layers are behind the firewall in an internal network. Do you happen
> to know if this will pose a problem with MSMQ?


As long as the necessary ports for MSMQ are opened in the firewall, no
problem. I don't recall which port (or ports) MSMQ uses, but I recall it
being easy to find. There's excellent support for MSMQ in the .NET
framework, so it's really easy to use, too.

-cd


 
Reply With Quote
 
William
Guest
Posts: n/a
 
      28th Aug 2006
"Carl Daniel [VC++ MVP]" <(E-Mail Removed)>
wrote in message news:%(E-Mail Removed)...
> Sure. Are there any particular parts that you're looking for help with?
> There's good support in .NET for all of the primitive bits that you'd need
> to build this.
>
> Given the kind of application you're describing, I'd think you'd want to
> write metrics to something like an MSMQ queue, not just a simple IPC
> queue, since then you'd get fault tollerance, crash recovery, and so on
> "for free" (of course, nothing's ever free). You could also use a SQL
> Server table, or if you're using SQL Server 2005, you could use SQL Server
> notification services (son of MSMQ) to queue the message to another
> process or thread.
>
> -cd
>
>


I am including a sample of what I have in mind if I do it in code rather
than MSMQ. I still have questions on:

1. Garbage collection since this is a web service. Will it only occur on
server reboot?
2. How should I control the thread. Should it just loop until the server is
rebooted as well?
3. Do I need a lock on the Queue object or is it enherintly threadsafe for
enqueue/dequeue?

CODE SAMPLE

[WebService(Namespace = "http://mycompany.com/b2bTestservices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestServices : System.Web.Services.WebService
{
Queue<TestTxnMetrics> metricsQueue = new Queue<TestTxnMetrics>();

static readonly TestServices instance = new TestServices(); public
static TestServices Instance { get { return instance; } }
static TestServices() { }

TestServices()
{
Thread thread = new Thread(new ThreadStart(UpdateTestBAM));
thread.Name = string.Format("UpdateTestBAM{0}", 0);
thread.Start();
}

[WebMethod]
public XmlDocument OrderTestCert(XmlDocument doc)
{
TestTxnMetrics metrics = new TestTxnMetrics();
metrics.TxnStart = DateTime.Now;

ITestOrder rObj =
(ITestOrder)Activator.GetObject(typeof(ITestOrder),
ConfigurationManager.AppSettings["TestRemotingServer"]);

string ret = rObj.PlaceTestOrder(doc.InnerXml, metrics);

XmlDocument retxml = new XmlDocument();
retxml.InnerXml = ret;

metrics.TxnEnd = DateTime.Now;
lock (this) { metricsQueue.Enqueue(metrics); }

return retxml;
}

private void UpdateTestBAM()
{
//loop this and sleep between loops. but how do I terminate it?
FloodTxnMetrics metrics = metricsQueue.Dequeue();
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Using a Singleton within a web service Ben Spigle Microsoft C# .NET 0 21st May 2008 11:17 PM
Application.Run and Windows Service (Multithreaded) Jake K Microsoft C# .NET 3 5th Jan 2007 07:48 AM
Web Service, Multithreaded, Logging to Database Stephen Carson Microsoft VC .NET 6 7th Apr 2006 03:27 PM
Singleton in web service? =?Utf-8?B?Qm9i?= Microsoft ASP .NET 5 23rd Dec 2004 03:34 PM
Multithreaded System Service Sonya Erb Microsoft VB .NET 3 17th Feb 2004 05:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 PM.