473,388 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Can a web service be implemented as a multithreaded Singleton?

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?
Aug 26 '06 #1
4 2194
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
Aug 26 '06 #2
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
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?
Aug 26 '06 #3
Thirsty Traveler wrote:
"Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospamwr ote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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
Aug 27 '06 #4
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
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<TestTxnMetricsmetricsQueue = 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();
}
}
Aug 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: noah | last post by:
Hi, I'm in the middle of writing a multi-user system with very critical timing issues. I've already implemented a cache and an API to access it (with appropriate locking for multithreaded access)....
11
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
1
by: ogled | last post by:
Hi I have a scheduler functionality that is implemented in public sealed class with static methods, and now i'd like to utilize it in a window service and have an exe file to access the...
1
by: A.J. | last post by:
I'm writing an application that will run as a Web Service. It will communicate with some old COM DLLs. These COM objects need to be called on their own thread. In a regular Web Service I would...
2
by: Fadi | last post by:
Backround: I am trying to figure out how to do the equivalant of a classic COM Local Server Singleton in .NET/C#. I created a coupld of simple Class Libs that exposes public interfaces and hosted...
5
by: Bob | last post by:
Does anyone know of any adverse affects of using singleton data access objects in an ASP.NET Web Service? I've been forced to implement it this way but it just doesn't seem right to me. I haven't...
4
by: SimpTheChimp | last post by:
I am going to write (my first) Windows Service. What I want is this service to run automatically when the computer/server is booted.... But also, to display an icon in the system tray whenever any...
3
by: Jake K | last post by:
I have a multithreaded application that I now want to convert into a Windows Service. Does application.run work in a windows service? Are there things to take into consideration when creating a...
3
by: Ronen Yacov | last post by:
Hi everybody, When declaring a singleton, we write: static CMySingle::instance() { static CMySingle instance; return instance; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.