What is the best choice to improve the performance of ASP? (1)

xiaoxiao2021-03-06  40

ASP developers are constantly working hard to achieve better performance and scalability in their design projects. Fortunately, there are many books and sites that provide good advice in this regard. However, these recommendations are the conclusions obtained from the structure of the ASP platform, and there is no measurement for the improvement of the actual performance. Since these recommendations require more complex coding processes and reduce encoding readability, developers can only measure whether their ASP applications can be paid in order to improve their ASP applications without causing actual operation.

This article is divided into two parts, I will introduce some performance test results to help developers to determine if a particular initiative is worthy of the future project, but can be updated for the original project. In the first part I will review some basic issues developed by ASP. In the second part, some Optimization ADO functions will be involved, and their results are compared to the ASP page that calls VB COM objects. These results are very eye-catching, even sometimes surprising.

In this article, we will answer the following questions:

* What is the most effective way to write ASP's content written in response stream? * Is the buffer should be turned on? * Do you should consider adding comments to the ASP code? * Is the default language should be explicitly set for the page? * If you don't need it, should you close the Sems status? * Whether the script logic should be placed in a subroutine and a function area? * What is the impact of using the included file? * What load is applied when performing error processing? * Set whether a context process has an impact on performance?

All tests are made with Microsoft's Web Application Key Tools (WAST), which is a free tool, which can be found here (http://webtool.rte.microsoft.com/). I created a simple Test script with WAST, repeatedly calls the ASP page test described below (more than 70,000 times). The reaction time is based on the average last byte total time (TTLB), that is, the time to receive the last bit data from the server from the server. Our test server is a Pentium 166, which is 196MB, and the client is Pentium 450, and memory is 256MB. You may think that the performance of these machines is not very advanced, but don't forget, we are not to test the capacity of the server, we just want to test the time used by the server each time you process. These machines do not do other jobs during the test. WAST test scripts, test reports, and all ASP test pages are included in the zip file (http://www.asptoday.com/articles/images/20000113.zip), you can review and test yourself.

What is the most effective way to write the content of the ASP in response?

One of the most important reasons used to use ASP is to generate dynamic content on the server. Therefore, it is clear that the starting point of our test is to determine the most suitable way to send dynamic content to the response stream. In a variety of options, there are two most basic: First, use the inline ASP tag, the other is to use the response.write statement.

To test these options, we created a simple ASP page that defines some variables and then inserts their values ​​into the table. Although this page is simple or practical, it allows us to separate and test some separate questions.

Use ASP inline mark

The first test includes using an inline ASP tag <% = x%>, where x is an assigned variable. So far, this method is the easiest to perform, and it keeps the page's HTML section a format that is easy to read and maintain.

<% OPTION EXPLICIT Dim FirstName Dim LastName Dim MiddleInitial Dim Address Dim City Dim State Dim PhoneNumber Dim FaxNumber Dim EMail Dim BirthDate FirstName = "John" MiddleInitial = "Q" LastName = "Public" Address = "100 Main Street" City = "New YORK "state =" NY "phonenumber =" 1-212-555-1234 "FaxNumber =" 1-212-555-1234 "Email =" john@public.com "birthdate =" 1/1/1950 "%>%>

Response test </ title> </ head> <body> <h1> response test </ h1> <table> <tr> <td> <b> first name: </ b> </ Td> <TD> <% = firstname%> </ td> </ tr> <tr> <td> <b> Middle Initial: </ b> </ td> <td> <% = middleinitial%> </ Td> <b> <tr> <td> <b> Last Name: </ b> </ td> <TD> <% = lastname%> </ td> </ tr> <tr> <TD > <B> address: </ b> </ td> <td> <% = address%> </ td> </ tr> <tr> <td> <b> city: </ b> </ td> <TD> <% = city%> </ td> </ tr> <tr> <td> <b> state: </ b> </ td> <td> <% = state%> </ td> < / TR> <tr> <TD> <b> phone number: </ b> </ td> <td> <% = phonenumber%> </ td> </ tr> <tr> <td> <b> fax Number: </ b> </ td> <td> <% = faxNumber%> <TD> </ TD> <TD> <B> Email: </ b> </ td> <td> < % = Email%> </ td> <b> Birth: </ b> <td> <td> <% = birthdate%> </ td> </ tr> </ Table> </ body> </ html> /app1/response1.asp full code</p> <p>Previously optimal (reaction speed) = 8.28 msec / page</p> <p>Use the response.write statement in each line of HTML</p> <p>Many better learning documents suggest to avoid using the previous method. Its main reason is that during the output page and the processing page to apply a reaction time, if the web server has to transform between sending pure HTML and processing scripts, there is a problem that is called context transformation. Most of the programmers heard here, their first reaction is to package the original HTML every line in the response.write function. ... response.write ("<html>") response.write ("<head>") response.write ("<title>") Response.write ("</ head>") response. Write ("<body>") Response.write ("<h1>") response.write ("<Table>") response.write ("<tr> <TD> <b> first name : </ B> </ td> <td> "& number") response.write ("<tr> <td> <b> Middle Initial: </ b> </ TD> <TD> "& MiddleInitial &" </ TD> </ TR> ") ...</p> <p>/App1/Response2.asp fragment</p> <p>Previously optimal (reaction speed) = 8.28 msec / PAGE reaction time = 8.08 msec / PAGE difference = -0.20 msec (decrease 2.4%)</p> <p>We can see that using this method is very small in performance as compared with the method of using the inline mark, this may be because the page is loaded with a large pile of functions to the server. The biggest disadvantage of this method is that since the HTML is now embedded in the script, the script code becomes more lengthy, more difficult to read and maintain.</p> <p>Use packaging functions</p> <p>When we try to use the response.write statement, the most discouraged discovery may be that the response.write function cannot be placed at the end of each row at the end of each line. Therefore, when you read the source code from your browser, it is very good HTML, and now there is no end. I think your next discovery may make you a horrible: there is no sister function writern in the response object. So, a significant reaction is to create a packaging function for the Response.Write function to add a CRLF to each line.</p> <p>... Writecr ("<tr> <TD> <b> first name: </ b> </ td> <td>" & numbertname & "</ td> </ tr>")</p> <p>... SUB WRITECR (STR) Response.write (Str & VBCRLF) End Sub</p> <p>/App1/response4.asp fragment</p> <p>Previous best (reaction speed) = 8.08 msec / PAGE reaction time = 10.11 msec / page difference = 2.03 msec (increasing 25.1%) Of course, since this method effectively doubles the number of function calls, its impact on performance Obviously, there is therefore avoiding every cost. Ironically, CRLF also adds two bytes to the reaction stream, which is that the browser does not need to be rendered on the page. Everything to format good HTML is to make your competitors easier to read your HTML source code and understand your design.</p> <p>Connect a continuous response.write into a separate statement</p> <p>Do not consider the test of our previous packaging function, the next logical step is to extract all the strings from a separate response.write statement, connect them into a separate statement, which reduces the number of functions It greatly improves the performance of the page.</p> <p>... response.write ("<html>" <"" "& _" <title> Response test </ title> "& _" </ head> "& _ <body>" & _ "<h1 > Response Test </ h1> "& _" <Table> "& _" <Tr> <TD> <B> First Name: </ b> </ td> <TD> "& firstname &" </ td> </ Tr> "& _ ..." <tr> <td> <b> Birth: </ b> </ td> <td> "& birthdate &" </ td> </ tr> "& _" < / TABLE> "& _" </ body> "& _" </ html> ")</p> <p>/App1/response3.asp fragment</p> <p>Previous best (reaction speed) = 8.08 msec / PAGE reaction time = 7.05 msec / page difference = -1.03 msec (decrease 12.7%)</p> <p>Currently, this is the optimized configuration.</p> <p>Connect a continuous response.write into a separate statement, add a CRLF at the end of each line</p> <p>Considering those who require their source code from browsers to see very purely, I use VBCRLF constants in the end of each row in front test, then re-run.</p> <p>... response.write ("<html>" & vbcrf & _ <head> "& vbrlf & _" <title> response test </ title> "& vbcrlf & _" </ head> "& vbcrlf & _ / app1 /RESPONSE5.ASP fragment</p> <p>The best (reaction speed) = 7.05 msec / page reaction time = 7.63 msec / page difference = 0.58 msec (increasing 8.5%) The results of the run in performance have a little reduced, which may be due to additional series and increased The word symbol.</p> <p>Review and observation</p> <p>Some rules can be obtained from the previous test of the ASP output:</p> <p>* Avoid excessive use of inline ASP. * Always connect a continuous response.write statement to a separate statement. * Never use the package function around Response.Write to attach CRLF. * If you must format the HTML output, CRLF is added directly within the Response.write statement.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-77631.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="77631" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.044</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'dvMlqVndI6_2FPEQWrLkFzMY_2FYiT4sO_2Fanr41HBdFxtHpxd39Cq_2B8PhMrK_2BLqX0I2URcC2znBQnXBEuSj9O4LOnw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>