在线用户    站点地图 技术论坛 文档中心 站点导航 资源下载 语言参考 教程专题 站点统计 业务项目 使用帮助
您的位置
MSDN参考新加了CSS2参考,全中文,制作精良。245k下载。           新加了sxf_sxf推荐的"动态网页专家指导" 下载!          新加了lsg2002lsg推荐的"ASP.NET高级编程(PDF)" 下载!          新加了DHTML代码预览!!,功能强大哦!欢迎试用          新加了网友lincong为大家提供的SQL Server 2000 程序员指南,有点大,但同时也就说明内容全咯!           新加了网友ibra为大家提供的北大的JAVA课件,很适合初学者入门           新加了一个java的连接缓冲池代码示例           新加了人月神话电子版下载!软件工程巨著哦~~           更新了评分标准,引入了“专家分”概念,相信可以更好的激励大家的学习!详情请看“使用帮助”           新加了由网友GGG提供的“IIS超级管理手册”,值得一看哦!(虽然我没看过 :P )           新加了“英雄榜”,欢迎测试!           “无组件上传·从原理剖析到实践”已经全部完成,源码全部开放,有兴趣的朋友请到文档中心一探究竟。  您的位置  首页>热点专题 在同一窗口中打开页面中的链接 在新窗口中打开页面中的链接 将ASPCHINA设为首页 将ASPCHINA加入书签    
 LOGIN HERE
用户:
密码: 忘记密码
记住密码 用户注册 游客进入
 SEARCH
Add to Google
 STATISTICS
总访问量: **
今日统计: **
注册用户: 14708
总论题数: 30886
总回复数: 112477
技术文档数: 938
 SURVEY
查看所有投票题目

Component vs. Component


Introduction


Almost every time you create components with Microsoft development products, you are creating your components as COM objects. These days, Component is a term frequently encountered by users of Microsoft development tools. There are business components, Active Server components, and Windows Scripting components, among others. In ASP, a component is code that is removed from an ASP page or an included source file and wrapped with a COM interface. It can be any of the aforementioned component types or have various other monikers.

For a COM object to be compatible with ASP it has to be a special kind of COM object called an Automation Object, meaning it supports Automation. Automation is a powerful extension of COM that allows the object to be leveraged by late-binding scripting languages, such as VBScript and JScript. Converting the bulk of your application code to a component architecture can increase the performance, scalability, and maintainability of your Internet application. But which of these technologies is best?

I have often wondered if a Windows Scripting component would be faster than an ASP page. I have pondered the same about compiled Active Server components. In this two-part article I will develop a small portion of an Internet Auction application using all three architectures. I will implement the database with Microsoft SQL Server 7.0. Code-wise, I will start with plain ASP pages, then migrate up into two other component architectures. In part one, I抣l implement the database and the ASP framework using Microsoft Visual InterDev. In part two I will first port the code into a Windows Scripting component, and from there to an Active Server Component built with Visual C++ 6.0 and the Active Template Library (ATL, a tool that is used to develop COM objects in C++). Finally, I抣l test the performance of the three architectures with WebLoad 3.5. The full source code for the database schema and all three components will be available for you to download. On top of that, the final functioning mini-application will be available for you to play with live on the Internet for at least 30 days from when this article is published.

Auction Sites Are Cool!


Some of the projects I worked on recently were Intranet projects for which scalability was not high on the list of requirements. I needed a scenario to develop around that if actually implemented in the real world, would require a highly efficient, scalable code architecture. I chose the Web-based Auction site. Since I enjoy buying and selling on eBay and thought it would be fun to toy with, so I decided to develop the searching functionality and the ability to open auction detail pages as the basis for this article. These two types of requests would be one of the most frequently hit on by auction enthusiasts like myself. It quickly occurred to me that I would need a database full of interesting auction items for users to search through and a full-text search engine for them to search with.

Data Modeling an Auction Site


My first draft of my auction model was nice and normalized, but it quickly became evident that perhaps a more flat approach would perform better. I also consulted Microsoft's Commerce Server Auction Component http://www.microsoft.com/siteserver/commerce/, which includes a sample auction data model. My model (see Figure 1) is much simpler than that on a real auction site. Only the tables and fields for my two primary tasks are present.

Figure 1

Users, Auctions, and Bids, Oh My!


To load realistic test data into an application for testing, I've frequently used Microsoft Excel as a test data creation tool. This technique fit this project as well. I needed a wagonload of users, auctions, and bids in my database so that I could accurately benchmark real-world performance. I made heavy use of VBA Excel Macros to create users, bids, prices, and date ranges. Then I used the LadLibs approach to create item descriptions and titles. I randomly combined a large list of verbs, adjectives, and description phrases. The result was 200,000 very strange items up for auction. Make sure to check out the http://c56387-a.mckiny1.tx.home.com/ to see what I mean. By saving the data into tab-delimited text files, you can use the Biphase Communication Processor (BCP), a command-line tool, to load the test data into the database very quickly. BCP is documented in the Microsoft SQL Server Books Online. Example 1 shows the BCP command I used to import the tab-delimited data.

Example 1

bcp auction..AUCTION in auctions.txt /e Eauction.txt -c -E -U sa -S MYMACHINENAME
..repeat for other tables. One text file per table

The Search for a Search Engine


Now that I had auctions with descriptions and titles, I needed a way to search them. I knew I would need a more powerful and faster text-search engine than the SQL LIKE %keyword% technique. LIKE would never perform to the level required by a popular auction site, nor is it very robust or accurate from the user's perspective. Microsoft SQL Server 7.0 includes a new full-text indexing service called Microsoft Search. This seemed like a good opportunity to put this new Microsoft tool through a few hoops, so I downloaded it at: http://www.microsoft.com/sql/bizsol/textsearch.htmand jumped right in.

Me vs. Microsoft Full-Text Search


Installing the SQL 7.0 Full-Text Search engine was easy. It's an optional feature not selected by default during SQL 7.0 setup, so you may have to run setup again to get it installed. However, getting it to work right was not simple. To support the Full-Text Search engine, new in SQL Server 7.0, Microsoft added some new Transact SQL functions. Getting these new full-text querying functions to work with parameters in a stored procedure is not as intuitive as I expected. It turns out you need to delimit the value of your parameters with a sometimes complex combination of single and double quotes, depending on how you want the engine to treat your search phrase. You cannot just retrieve a search phrase from the user, pass it into a stored procedure, and then use the variable as a parameter to the Transact SQL functions. I found some help on microsoft.public.sqlserver.programming, and Example 2 demonstrates my results in in the stored procedure FetchSearchResults. This procedure handles both the simple and advanced search forms. The only other procedure is FetchItemDetail, which simply fetches everything needed to display an auction item's detail page, given a primary key. There are more advanced features of the full-text support functions that I chose not to use for sake of simplicity.

Example 2 fetchSearchResults

CREATE PROCEDURE AUSP_fetchSearchResults  
(
 @searchphrase varchar(100), 
 --text to look for  (simple and advanced search)
 @minprice money = -1, 
 --low price range to include (advanced search form)
 @maxprice money = -1, 
 --high price range to include (advanced search form)
 @orderby varchar(20) = "end_dt", 
 --order by this field (advanced search form)
 @sortdesc int = 0, 
 --use TSQL DESC keyword if = 1 (advanced search form)
 @both int = 0 
 --search both title and desc indexes 
 --if = 1 (simple and advanced)
)
AS
set ROWCOUNT 500 --max # of rows a search will find
declare @sql varchar(1024) --local var for sql string

set @sql = 'SELECT a.auction_seq, a.auction_type_seq,' & _
      'a.title, a.end_dt,a.current_price,' & _
	  'COUNT(bid.bid_seq) AS bid_count, TXTTBL.RANK '

if @both = 1 	--search both full-text indexes, use '*'
set @sql = @sql + 'FROM auction a INNER JOIN
freetextTABLE(auction,*,''" '+@searchphrase+' "'')
AS TXTTBL ON a.auction_seq = TXTTBL.[KEY] '
else		--search only title
set @sql = @sql + 'FROM auction a INNER JOIN
freetextTABLE(auction,title,''" '+@searchphrase+' "'')
AS TXTTBL ON a.auction_seq = TXTTBL.[KEY] '

...further building of SQL where clause omitted for brevity
	
--select @sql as sqlstring --for debugging
exec(@sql)
Although it seemed logical to me, TSQL syntax does not support using the @searchphrase parameter directly with the new full-text query functions. You have to build an SQL statement dynamically inside your procedure code, combining the search phrase the user has chosen with standard SQL (see Example 3). I could not come up with a better way, and reportedly many developers are using this approach. Example 3

This works:

set @sql = @sql + 'SELECT * FROM auction a
INNER JOIN freetextTABLE(auction,*,''"
+@searchphrase+' "'') AS TXTTBL ON
a.auction_seq = TXTTBL.[KEY] '
exec (@sql)
The following does not work, but it would be great if it did:
SELECT * FROM auction a INNER JOIN
freetextTABLE(auction, *, @searchphrase)
AS TXTTBL ON a.auction_seq = TXTTBL.[KEY]
Another delay was caused by the way the query engine sorts a result set that is ordered by the full-text search's rank field. The new Freetexttable( ) Transact SQL function creates an additional column in the resultset, which is a numeric accuracy ranking. A higher rank number is better than a lower one. That seems logical, however, if you do not use the Descending keyword, the resultset will be in backward order by rank. That is because the Order by clause sorts the Lank column as it would any other numeric column, from lowest to highest. The hits that least match your search phrase will be at the top. It is all clear to me now, but this eluded me for a while.

A final complication introduced into the development process by the Full-Text Search Service is that you are not allowed to make a schema change to any table that has been full-text indexed. You can't even make small changes to fields and indexes that are unrelated to the full-text indexed fields, unless you remove full-text indexing from the table first. Depending on the change you make, you may have to repopulate the full-text index again. Full repopulation is a chore than renders my database server (albeit not production-quality equipment) useless for about three hours. If you had an environment with more than a million rows of full-text indexed data this process could really become a burden. The engine did perform very well, and the functions provided are very robust. In some quick tests I ran the Full-Text search engine, which beat the heck out of the old LIKE-clause method. Once my data was in place and my stored procedures written, it was time to get busy with some ASP.

Disconnected Recordsets


In a high-performance Web application it is very important to open and close a database connection as fast as possible. Efficient use of database connections when using Microsoft's ActiveX Data Objects (ADO) can be achieved through disconnected recordsets (see Example 4). Microsoft Data Access Components, the key technologies that enable Universal Data Access, include the ActiveX Data Objects, among others. A disconnected recordset is an ADO Recordset object that is full of resultset data but has had it's ActiveConnection property set to Nothing. Don't try this with a regular recordset. You have to use a special CursorLocation value to achieve thisExample 4
Dim oConn
Dim oRS
	
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Article.Auction;"
	
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient  
'NOTE: This is important for Disconnected Recordsets
oRS.Open "AUSP_fetchAuctionDetail " & lAuctionSeq, & _
oConn, adOpenStatic, AdLockReadOnly
		
oRS.ActiveConnection = Nothing
oConn.Close
Set oConn = Nothing
The first thing my two ASP pages do when processing a search request or an individual auction detail request is retrieve the data and disconnect the recordset immediately. There is a VBScript function for each task, fetchAuctionDetail() and fetchSearchResults(). These functions share the name of their respective stored procedure counterparts. Both functions take a reference to a recordset object and then fill that recordset object with data. As soon as the data is available, the Recordset is disconnected. By the time the first line of HTML text is written through the Response object, the database connection is closed. The only task left is formatting that data into a usable Web page. While the Web server is performing the task of formatting the page with the data, the database server has been freed from any more duty. It is now available to handle requests from some other client. This is efficient and is highly scalable. It could be thought of as a 揋et iIn and Get out as fast as possible approach to database access. I used disconnected recordsets in all three architectures (the ASP, Windows Scripting Component, and Active Server Component built in C++). You could speed up the code even more by explicitly defining your stored procedure parameters with a cCommand Object.

For more information on enhancing your ASP performance see this article in the October issue of MIND, http://www.microsoft.com/mind/1099/inthisissue1099.htm.

<% Tag Time %>


Although I am a big fan of eBay's site, I'm not a fan of their visual design. As I re-created an eBay-like search page, search results page, and auction item detail page, I made a few visual enhancements. I slapped on the Verdana font and got rid of the hospital-gown-green table backgrounds. I also coded some of the necessary minor functions that are needed by the detail page, such as changing the presentation of some of the data depending on the value (see Figure 2). An example of this is the Time left string. This has several different looks, depending on how much time is left until the auction ends.

Figure 2

The Search Page


There are many different ways to search the eBay database. I re-created three of them - the simple search, the advanced search, and the item number search. The item number search just redirects you to the item detail page, item.asp. The search page is completely static and remains unchanged for all three versions. The hard work of providing results is handled by results.asp. The code structure in results.asp is much like item.asp, except the output HTML is different. The finished working demo returns up to 500 search hits in pages of 50-items each (see Figure 3).

Figure 3


Include Dude


I love server-side <!-- #include --> statements. They allow you to develop modular, re-usable, maintainable ASP code, instead of behemoth, memory-hogging, difficult-to-maintain pages. Applying the object orientation, abstraction, and reusability principles of more robust programming languages to the ASP development platform will take you a long way towards a successful application, even if you are just sticking with plain ASP. In my first implementation of this application, I created several functions in an included ASP file. Developing your code with reusable includes also does something else that is very important for this article and for anyone who wants to leave their future options open. It makes converting to any of the Component architectures extremely simple. Your code will already be structured like it is accessing the code in a reusable object. However, it will be without one layer of abstraction, the COM interface your Windows Scripting Component will expose. Figure 4 depicts the Part I code architecture of my two ASP pages and their included library of functions.

Figure 4

To Be Continued


In the second half of the article, I will convert the pure ASP and include file architecture to a Windows Scripting Component and also an Active Server Component written in C++. Then I will load test all three.

Download


The database scripts, BCP code, and ASP application source are available for download here.
ftp://ftp.15Seconds.com/991028.zip

PART II                Back To Top


您的位置
  (c)2000-2019 Yup Studio, all rights reserved.  
7.8125