Performance notes and comparison with FileSystemObject and its use to do log files in ASP.
|Maybe, you need some logging for your asp application. You want to log current time and some other values to the log file and you need to have daily logs. This page contains some small info about performance and locking problems in ASP.|
<% .... DoLogFS1 "Some log value" Function DoLogFS1(LogLine) Dim OutStream, FileName Const LogSeparator = " " FileName = "D:\LogFiles\fs1" & Right("0" & _ Year(Now), 2) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & ".Log" Set OutStream = CreateObject("Scripting.FileSystemObject").OpenTextFile _ (FileName, 8, True) OutStream.WriteLine Now() & LogSeparator & LogLine End Function %>
| Simple function. But it takes most
of the time to create filesystem
2. You can put the FileSystemObject to global.asa and modify your function:
<Object RunAt=Server ID=FS ProgID=Scripting.FileSystemObject Scope=Application></Object>and use the FileSystemObject i your ASP page:
<% .... DoLogFS2 "Some log value" Function DoLogFS2(LogLine) Dim OutStream, FileName Const LogSeparator = " " FileName = "D:\LogFiles\fs2" & _ Right("0" & Year(Now), 2) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & ".Log" Set OutStream = FS.OpenTextFile (FileName, 8, True) OutStream.WriteLine Now() & LogSeparator & LogLine End Function %>
This function takes 4 times less time than version 1. But this function takes most of the time to open log file for append.
3. We can do last optimalization - store the file stream in application :
<Object RunAt=Server ID=FS ProgID=Scripting.FileSystemObject Scope=Application></Object> <SCRIPT LANGUAGE=VBScript RUNAT=Server> Sub Application_OnStart Dim OutStream, FileName FileName = "D:\LogFiles\fs2" & _and use the stream i an ASP page:
Right("0" & Year(Now), 2) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & ".Log" Set OutStream = FS.OpenTextFile (FileName, 8, True) Set Application("OutStream") = OutStream End Sub </SCRIPT>
<% .... DoLogFS3 "Some log value" Function DoLogFS3(LogLine) Const LogSeparator = " " Application("OutStream").WriteLine Now() & LogSeparator & LogLine End Function %>
The codes number 1. and 2. have also also another problem - simultaneous requests. When the page is used by many browsers, open of the log file for append may fail. For example, if you do 10 000 requests from 10 browsers to the page, you wil have 9542 records in your log file (or similar number). Some log records will be lost because first call of OpenTextFile for append locks the log file and second call from another request will fail.
The code number 3 solves the problem, but you have another problem - now you have no daily logs, but only one log with date of start of ASP application.
4. We can compare performance of a best solution for the problem, LogFile class. The class solves problems with daily file name, simultaneous requests and many other problems and tasks. Global.asa:
<Object RunAt=Server ID=LogFile ProgID=ScriptUtils.LogFile Scope=Application></Object> <SCRIPT LANGUAGE=VBScript RUNAT=Server> Sub Application_OnStart LogFile.TemplateFileName = "D:\Log\LG%y%m%d.Log" End Sub </SCRIPT>ASP page:
<% .... LogFile.Log "Some log value" %>
|Next table contains a short performance comparison of the four source codes. The times was from PII Celeron/500MHz.|
|1. Simple FileSystemObject||3 800|
|2. FileSystemObject in Application||950|
|3. TextStream in Application||150|
|4. LogFile class||60|
Dim vCurr, vDbl, vStr, vDate, vEmpty vCurr = CCur (256.235) vDbl = CDbl (23215.132154) vStr = "Some string value" vDate = Now
DoLogFS4 vStr & LogSeparator & vCurr & LogSeparator & _ vDbl & LogSeparator & vDate & LogSeparator & vEmpty or LogFile.Log vStr, vCurr, vDbl, vDate, vEmpty
|You can see that LogFile class has at least 2 times better performance than text Stream from FileSystemObject. And the class solves many other problems and work with logging ...|
Huge ASP upload is easy to use, hi-performance ASP file upload component with progress bar indicator. This component lets you upload multiple files with size up to 4GB to a disk or a database along with another form fields. Huge ASP file upload is a most featured upload component on a market with competitive price and a great performance . The software has also a free version of asp upload with progress, called Pure asp upload , written in plain VBS, without components (so you do not need to install anything on server). This installation package contains also ScriptUtilities library. Script Utilities lets you create hi-performance log files , works with binary data , you can download multiple files with zip/arj compression, work with INI files and much more with the ASP utility.
© 1996 - 2011 Antonin Foller, Motobit Software | About, Contacts | e-mail: firstname.lastname@example.org