Web service performance issue

I have a simple asmx webservice that just needs to log some information to a transactional database. However, it's time for the client. The call to update the database just calls 1 stored procedure and I don't believe it could be optimized for better performance. I boiled down to simple logging of a run using log4net and then reading the log in a separate process that updates the database.

I was wondering if there is a better way to do this. I was wondering if there is a way to get my code to do something like:

public bool method(...)
{
  LogRun(...)

  Asynchronously call method to insert transaction

  return true;  
}

      

+1


source to share


5 answers


EDIT: I was wrong about BackgroundWorker. So I checked it for Thread version, tested.

If you want the job to run asynchronously, you can learn how to start another thread.

public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public void Log(int foo, int bar)
    {
        Thread a = new Thread(new ThreadStart(delegate()
        {
            // Do some processing here
            // For example, let it sleep for 10 secs
            Thread.Sleep(10000);
        }));
        a.Start();
    }
}

      



It took 10 seconds for the Log method to complete processing if the Thread.Sleep (10000) line is in the log method itself. However, with Thread a, the Log method will return immediately after being called.

Also note that there is no easy way to guarantee the calling client if the insert operation is complete or not with this asynchronous calling style.

0


source


One thing you can try is Tracing .



0


source


If the query cannot be optimized, you can increase the timeout value for your SQL client , assuming you can use SQL server.

On the client side that is consuming the web service, you can use this method asynchronously if you want the client to keep doing other operations. When the web method is complete, it will fire an event. There is a small example you can read here if you think it might help.

0


source


While you can see how to do asynchronous operations inside your web method, you are working with threads and / or file pool inside asp.net, which already has multi-threaded operations in the game. While technically possible, you can also inadvertently loot the resource system as httpruntime manages resources when serving requests to your service.

Writing to a local log4net file and importing that data in a stand-alone routine is higher availability than real-time logging, asynch or otherwise, as your sql server might be offline and your service is still available. If you don't need sql server for anything other than logging, prefer to keep db operations from a web method.

0


source


If it's just a fire-and-shoot call for the client, your web service can simply queue up data and return to the client. I used MSMQ to implement something similar to what you are describing. It does not set a database timeout, but it does accept an error message from your clients.

0


source







All Articles