Re: Thread.Sleep or Timer in a web service - which is proper??
In a strict ajax post/response to a web service you get the response immediately.
I've got a setup where a report is produced by a .bat file running on the server - it's Process.Start'd by another web service.
When that report process completes it sets a value in a table saying that report 000123 is now done.
I want the browser to know this fact as quickly as possible.
Most reports run quickly - under 60 seconds - but some can take several minutes.
I was hoping that the first AJAX call to see if the report was done would actually look for a while - up to a minute maybe - with checks to the DB occuring every 250 ms maybe. That way the instant (at least 250ms instant) the DB knows the report is done the response to the client happens...
If that first AJAX call did not see that the report was done - the browser would then wait a bit (1000 ms at this time) and then re-send an AJAX call to the server for status update.
This would happen over and over again until said report is completed...
It is actually working with the code I posted in that other thread. I just don't know how scaleable this is going to be.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: Thread.Sleep or Timer in a web service - which is proper??
Originally Posted by szlamany
In a strict ajax post/response to a web service you get the response immediately.
I've got a setup where a report is produced by a .bat file running on the server - it's Process.Start'd by another web service.
When that report process completes it sets a value in a table saying that report 000123 is now done.
I want the browser to know this fact as quickly as possible.
Most reports run quickly - under 60 seconds - but some can take several minutes.
I was hoping that the first AJAX call to see if the report was done would actually look for a while - up to a minute maybe - with checks to the DB occuring every 250 ms maybe. That way the instant (at least 250ms instant) the DB knows the report is done the response to the client happens...
If that first AJAX call did not see that the report was done - the browser would then wait a bit (1000 ms at this time) and then re-send an AJAX call to the server for status update.
This would happen over and over again until said report is completed...
It is actually working with the code I posted in that other thread. I just don't know how scaleable this is going to be.
Where do you start the Process.Start method. Is it inside the webservice call method ?
Is it a bad practice? Tough call. My gut says yes. Web Services, and Web Applications are meant to be stateless. Introducing a Timer, in my opinion, is building in at least some form of state, and should be avoided. If we are talking the difference of waiting an extra minute to get the report as a result of a poll from the client, is that really such a bad thing?
Could your back end service not email a link, or for that matter the report itself, to the user when it is ready?
Re: Thread.Sleep or Timer in a web service - which is proper??
Let me argue a different point of view...
If I has a web service that actually created reports - PDF's or whatever output format - would it be acceptable for that web service to take 60 seconds to run. So POST comes in and no response for 60 seconds...
Or would you expect the web service to off-load the report creation to some other application on the server - so the POST for the report comes in and the response is immediate??
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: Thread.Sleep or Timer in a web service - which is proper??
Hello,
That really depends on what you want to do on the UI during this time.
Do you want the user to interact with your application while the report is being generated, or do you want them to be presented with some form of waiting dialogue while it is happening.
Depending on the application, both are perfectly valid.
For what I am working on just now, we make the call to our Web Services asynchronously, allows us to continue work on the UI while waiting for the callback from the method.
Re: Thread.Sleep or Timer in a web service - which is proper??
Same here - all the async calls I do leave the UI free - user can change jQuery TABS and work on other grids - I just make sure to lock-up whatever I need to on the tab that is waiting.
There are times where the app waits for initial autocomplete data to come in and I make sure to read-only those dropdowns until the data is available.
My question was specifically about the SERVER thread running the web service.
Are you comfortable with a web service taking 60 seconds to complete a task? Does that lead to scalability issues?
The whole point of this conversation is to alert the user as quickly as possible that a task is complete on the server.
Considering my options - would you do #1 or #2?
1) Make an ajax request every 250 ms to the server for the report status
2) Make an ajax request every minute to the server and have the server respond as soon as it knows the task is complete - basically web service loops internally every 250 ms so the response is instant - at one minute it returns status of "still waiting" and client makes another ajax request
3) Is there any other option?
Here's a screen shot of the REPORT selection - then clicking the PRINT ICON to start the report - and a screen shot to the right of that showing a report getting QUEUE'd because one is not done and then what it looks like when the status comes back completed.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: Thread.Sleep or Timer in a web service - which is proper??
Hello,
How many users are we talking about, and how many reports are they doing on a daily basis?
If you are going to have say 1000 users, doing a report at the same time every day, then doing a AJAX call every 250 ms to the server is going to rack up.
I see what you are getting at, and what you are trying to achieve, but is this an over complication? Is this an explicit requirement, or a nice to have? For instance, could you not simply have a refresh button that the user could click to check whether the report is ready?
If you have to do this, and your options are 1 or 2, then I would say number 2.
Re: Thread.Sleep or Timer in a web service - which is proper??
My clients are complaining about having to hit a SAVE button - used to enter data in a VB6 msflexgrid and I would autosave at the end of each row!
They are going to complain that the report doesn't just download automatically - why do they have to click the PRINTER ICON to start a report and then wait until it says it's ready to download - and "what do you mean I've got to click DOWNLOAD?!!?!??!".
When you write custom software for clients - and want to get paid the best $$'s - they are always right. Customer is always right
Initial use will be dozens of users - running several reports a day.
But I've got clients with 100's and even one with 1000+ users with the old VB6 app - when we migrate them things are going to have to scale.
At this point I've tested this code - and my CPU on my development machine does not go crazy. I do not want to use a TIMER as that starts on another thread and that seems really dangerous in IIS as it's got it's own threading issues to deal with. I'm going to move the DB CONNECTION OPEN outside the loop - no reason to open/close a connection 20 times in a loop...
Code:
If ctrloption = "reportstatus" Then
Try
Dim maxloop As Integer = 20
Dim curloop As Integer = 0
Do While strMessage <> "C" And curloop < maxloop
Using dcn As New SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("LocalSQLServerAWC").ToString)
Using cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "dbo.awc_ReportGetStatus"
cmd.Connection = dcn
cmd.CommandTimeout = 0
DetermineParameters(dcn, cmd)
cmd.Parameters("@RptId").Value = ctrlval1
dcn.Open()
strMessage = cmd.ExecuteScalar().ToString
End Using
End Using
If strMessage <> "C" Then
curloop += 1
Threading.Thread.Sleep(250)
End If
Loop
.NewObject("reportstatus", "true")
.Seperate()
.NewObject("rptid", ctrlval1)
.Seperate()
Catch ex As Exception
strSuccess = ""
strMessage = ex.Message
End Try
End If
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".