views:

3632

answers:

11

I'm doing some revision on an old app that is written in classic ASP/VbScript.

It has a feature to send out an e-mail to the members of the application, but because the member list is quite large, the server rejects new e-mails after the first hundred or so are sent.

I've written some code to make it send out e-mails in burst of 20, but this still doesn't work. I think that perhaps making it sleep for a second between burst might work properly.

However, I can't seem to find a Thread.Sleep type method in VbScript.

Is there one?

+2  A: 

Not to my knowledge. You'll have to use some external code written in class VB or whatever to do it.

Or busy-wait (gak).

1800 INFORMATION
Is it possible to install a hand written COM component on a shared server?
FlySwat
I guess you'd need administrator approval to do that
1800 INFORMATION
Yeah that won't happen :(
FlySwat
Then you should busy-wait as punishment! Don't let me install software will you? muahahaha
1800 INFORMATION
+1  A: 

You know, this is one of those times that I think setting up a private MSMQ queue could be a Good Thing. Put the emails you want to send on the queue, and have a newly developed .NET service do the sending. That will free up your ASP.NET application, and allow you to manage your sendin' centrally!

Dave Markle
+2  A: 

This looks like a good hack:

http://www.ehow.com/how_2001270_sleep-asp-using-ado.html

The trick is to create an ADO connection object and then try to connect to a non-existant server. This will block for the duration of the connection object's timeout setting.

MusiGenesis
nice clever hack.
tyndall
@Bruno: I liked it, too, but I disavow all responsibility for it. :)
MusiGenesis
+3  A: 

there is also a good hta hack that should work. Look for the A Synthetic Sleep Function here: http://www.mvps.org/scripting/rube/index.htm

mrTomahawk
+1  A: 

Be aware that IIS has a default ASP Script execution time-out default of 90 seconds, so running large scripts that send volumes of email this way will time-out unless you change the asp timeout.

Nick Kavadias
+2  A: 

Do you want me to write you a super simple sleep routine you can call in ASP? It's super simple, and I may have already done it, and have the source sitting around somewhere.

Don't use hacks, please. That just leads to broken code later on, and unexplained activity by the code.

Larry

LarryF
Larry, I don't think I can install a COM component on a shared server, otherwise I'd have gone that route already.
FlySwat
A: 
shahkalpesh
using this sort of loop will probably end up in 100% CPU usage. This is known as a "Tight loop", and is not recommended...
LarryF
So what is wrong with that? Did you see that it is using 100% CPU?
shahkalpesh
Yeah this is a spinning wait, its a horrible thing.
FlySwat
To elaborate, on a shared server, I'd max out the core I'm running. This means any other threads (and there will be other threads) don't get the same CPU time.Run your example on your machine and watch the CPU usage.
FlySwat
Keeping in mind that on modern multi-core CPU's, it will only REALLY show 50% usage, because only a single core is maxed out. Run two copies of this to see what we're talking about.
LarryF
Thanks Guys. Now, I understand that it will not release control for other threads to run. Is my understanding correct?
shahkalpesh
@shahkal - Yea, pretty much. Some CPU time will be given up to other threads in the scheduler, but not many. At the process level, anyone with NORMAL or below priority will not be given any slices.
LarryF
A: 

Jonathan, what code are you using to SEND the emails? Maybe there is something there that we could use to help solve the main issue. Maybe sleeping isn't the best way to go, and there is perhaps something else that can be done.

I commented on shahkalpesh's code sample, that it would tight-loop, and cause too much CPU usage. (Sure, it may be superficial, but still not proper, and the more sessions you have going, the worse it will get). But, you COULD use his code if there was something inside the loop that was waiting on something else, like a remote server, or a DNS request, a response from a mail server, SOMETHING...

It's too bad about the COM object... That's a sweet way to go. I do know that the WSH has a Wait, (or sleep, I forget) built in, but that's only available under WSH, or CSH. Now, you MIGHT be able to create an object of WShell in your ASP and use some functions out of there to get a simulated sleep or some other non-intense operation.

Just MHO...

Larry

LarryF
Larry, does it really make it bad for a 10 seconds sleep? Also, what other things can be done while something in being executed in current session context? Lets assume that you try to connect to a DB (that you cant do anything while its executing). Whats wrong with sample code?
shahkalpesh
@shahka, the difference is, when you are trying to connect to a DB, the code enters a "wait state", (like a callback), so no CPU time is used. It matters not about what the SESSION or THREAD is doing, it matter what ELSE the CPU/Core is doing.
LarryF
For an example, find an older non-multi-core CPU. Setup your sample to sleep for 10 seconds, then run for 2-5 seconds or so, then sleep again for 10. Do that about 20,000 times. While it's running, try and use box, see just how responsive it is. Move windows around, watch the CPU usage, etc.
LarryF
+1  A: 

Sorry that this answer is not strictly related to the question, but in trying to answer a question, it just got way to big for comments.

@shahka, the difference is, when you are trying to connect to a DB, the code enters a "wait state", (like a callback), so no CPU time is used. It matters not about what the SESSION or THREAD is doing, it matter what ELSE the CPU/Core is doing.

For an example, find an older non-multi-core CPU. Setup your sample to sleep for 10 seconds, then run for 2-5 seconds or so, then sleep again for 10. Do that about 20,000 times. While it's running, try and use box, see just how responsive it is. Move windows around, watch the CPU usage, etc.

THAT gives you an exmaple of what's happening to this man's Web server. It becomes unresponsive, because the thread scheduler will tend to 'favor' the CPU/Core that is NOT "spun up" (as we call it). So, ALL web requests, OS operations, etc will happen on the OTHER core, thus over-loading it, giving it a feeling of being "spun up" as well.

Now, you have times when you can tight-loop a CPU and it will not matter. But, in all my years of programming, I've never found it necessary to write a tight loop like that (on purpose). Some of it comes back around to doing things the right way, and the wrong way. Doing something the wrong way will often WORK, but that does not mean it wworks CORRECTLY.

If you want a good example of this, go and pick just about any virus on the planet, and analyze it. You'll find that it order to do damage, they (virus writers) often have to do things the "wrong" way. Sure, it gets the job done, but it also breaks the virus on say, a different language version of Windows, or it crashes the whole machine negating it's purpose, etc.

Greg Hewgill was one of my early teachers about this type of stuff, and since I worked with him for many years, and supported, and later QA'ed his software, I learned a lot from him, much in the same waay I'm trying to tell you why your code sample is not good. strictly speaking, the code is fine. It works. It's well written. But, it does not FUNCTION correctly, and has adverse side effects that other, maaybe amature programmers who might be reading this looking for knowledge do not fully understand. THAT'S why I did not recommend your sample.

LarryF
+1  A: 

shahkalpesh's approach is 100% NOT the way to do it. This will peg your CPU for the duration of the Sleep() function. Pegging the CPU is very, very BAD!

A: 

Perfect!! Thank's Guy