We are going to discuss the topic with example.
Because a web service requires the exchange of network messages and because the server that executes the web service may be busy performing other tasks (thus delaying its execution of the service you desire), a web service will execute much slower than a standard function.
To get the feel (to verify) of this Overhead let’s create a short & simple test:
Step 1: Create a Web Service and write down a simple Hello World method as shown below:
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
Step 2: Now, create a simple Web Application and create the same private method in the web page:
private string GetHelloWorld()
{
return "Hello World";
}
Step 3: Now create two buttons followed by label on the page as shown:
Step 4: Finally you are ready to call these two methods on click:
protected void btnLocalCall_Click(object sender, EventArgs e)
{
HelloWorld.Service1 hello = new HelloWorld.Service1();
long start_tick, end_tick;
start_tick = DateTime.Now.Ticks;
for (int count = 0; count <>
{
lblLocalCall.Text = GetHelloWorld();
}
end_tick = DateTime.Now.Ticks;
lblLocalCall.Text = "Tick: " + (end_tick - start_tick).ToString();
}
protected void btnServiceCall_Click(object sender, EventArgs e)
{
HelloWorld.Service1 hello = new HelloWorld.Service1();
long start_tick, end_tick;
start_tick = DateTime.Now.Ticks;
for (int count = 0; count <>
{
lblServiceCall.Text = hello.HelloWorld();
}
end_tick = DateTime.Now.Ticks;
lblServiceCall.Text = "Tick: " + (end_tick - start_tick).ToString();
}
Result: Just check the results below:
When the user clicks the “Call Local..” button, the program code will call the local functions within a for loop to get values 100 times. Because the functions reside in RAM, the program can complete its processing very quickly. When the user clicks the “Call Service…” web button, the program will use the “HelloWorld” web service methods within a for loop to get values 100 times. The network overhead of the web service calls causes the operations to execute much slower. The program displays the number of clock ticks each swap operation required within the text boxes.
Because network overhead makes a web service execute much slower than a standard function, many operations are not well suited for implementation as a web service. Using a web service to add two numbers, for example, or to calculate a random number, would introduce unnecessary overhead to a program. Such operations are better suited for implementation using standard functions.
Web services, in contrast, are ideal for operations that use data residing at a remote source (most often within a database on a specific server). For example, web services are well suited for the following operations:
- Responding to queries for stock quotes
- Returning information regarding the availability of specific inventory items
- Providing real-time information, such as weather and road conditions
- Offering airline flight arrival and departure information
- Implementing e-commerce operations, such as ticket sales for movies and special events
- Authenticating users or credit-card information
You may be saying to yourself that users already perform such operations on many sites across the Web. Web services provide programmers with a way to integrate these operations into their programs. By using web services to implement common user operations (such as downloading stock quotes, ordering a book, and checking the weather) within your company’s website, you can keep users from leaving your website to perform these operations elsewhere. By taking advantage of web services, you can integrate powerful processing developed by other programmers into your applications and web pages.
One can cross check calling second web service within the first to check the overhead, it goes twice.
Hope this helps you understanding Web Service Performance Overhead.
Ref:
.NET Web Services Solutions | |
by Kris Jamsa | |
Regards,
Paresh Bhole
1 comment:
public string HelloWorld() { return "Hello World"; }
Could be seen as a constant. And if you also would say: 'it`s a public hello' than it could also be cached public....
So, maybe WebServices are goging to be a lot faster and intelligent in the future.
Post a Comment