Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 Suggestion for chkUser() & new index
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

work mule
Senior Member

USA
1358 Posts

Posted - 19 July 2003 :  16:55:53  Show Profile
I have a suggestion regarding the chkUser() function and a new index for MSSQL users.

1. Create an index on m_name (either clustered or non-clustered).

2. Change the chkUser() function to the following:



function chkUser(fName, fPassword, fAuthor)

   dim rsCheck
   dim strSql

   '## Forum_SQL
   strSql = "SELECT MEMBER_ID, M_LEVEL, M_NAME, M_PASSWORD, M_STATUS "
   strSql = strSql & " FROM " & strMemberTablePrefix & "MEMBERS "
   strSql = strSql & " WHERE " & strDBNTSQLName & " = '" & ChkString(fName, "SQLString") & "' "
   Set rsCheck = my_Conn.Execute(strSql)
   if rsCheck.BOF or rsCheck.EOF or not(ChkQuoteOk(fName)) or not(ChkQuoteOk(fPassword)) then
      MemberID = -1
      chkUser = 0 '##  Invalid Password
      if strDBNTUserName <> "" and chkCookie = 1 then
         Call ClearCookies()
         strDBNTUserName = ""
      end if      
   else
      if rsCheck("M_STATUS") = 1 and ((strAuthType="db" and fPassword=rsCheck("MEMBER_ID")) or (strAuthType<>"db")) then
         MemberID = rsCheck("MEMBER_ID")
         if (rsCheck("MEMBER_ID") & "" = fAuthor & "") and (cLng(rsCheck("M_LEVEL")) <> 3) then 
            chkUser = 1 '## Author
         else
            select case cLng(rsCheck("M_LEVEL"))
               case 1
                  chkUser = 2 '## Normal User
               case 2
                  chkUser = 3 '## Moderator
               case 3
                  chkUser = 4 '## Admin
               case else
                  chkUser = cLng(rsCheck("M_LEVEL"))
            end select
         end if   
      else
         MemberID = -1
         chkUser = 0 '##  Invalid Password
         if strDBNTUserName <> "" and chkCookie = 1 then
            Call ClearCookies()
            strDBNTUserName = ""
         end if      
      end if
   end if

   rsCheck.close   
   set rsCheck = nothing

end function




How I arrived at this.

We launched the forums on our Trains.com site (still working an a couple of things ). The site has 116K+ registered members to whom we sent out an announcement a couple of days ago, inviting them back.

Well, within minutes the traffic on the site spiked and everything slowed down to the point of being unuseable. It was pretty bad. I felt like I was in the middle of an IBM commercial. Checked the webserver and it was fine. Checked the database server and that sucker was pegged. Within a couple of hours, the number of visitors dropped and the site was slow but useable.

The next day I ran a couple of profiles against the database and before I left I ran the index tuning wizard against the trace file on our development box. It took about 8.5 hours.

While watching the one trace running (using the wizard option for worst query performance) I noticed the slowest queries was the select statements with m_name, m_password, m_status in the where clause. The results of the wizard suggested creating a clustered index on the m_name field, an non-clustered index on m_name, m_password, m_status, and a few others.

Thinking about the queries I had seen, I realized it was the chkUser function. The first thing that happens when someone visits the forums, or the rest of the site for that matter, the query runs looking for m_name, m_password, m_status which didn't match any indexes and forced a tablescan against 116k+ records. Having to scan the password field for 64 character strings probably didn't help.

Of course I could accept the recommendation of creating an index on the three fields, however it struck me I could do something better.

I created the clustered index. Then I modified the function so that the SQL statement only searched on the username (m_name). The password and member status fields were already include in the select statement, so when the matching record was returned, I compared the password values and checked the member level.

The result was that now the performance of the site is significantly faster than it has been. An unexpected side benefit is the Members page returns search results faster -- especially when searching on username or names starting with one of the letters.

Edited by - work mule on 20 July 2003 10:18:11

bjlt
Senior Member

1144 Posts

Posted - 20 July 2003 :  03:50:22  Show Profile
if rsCheck("MEMBER_ID") = 1 and ((strAuthType="db" and fPassword=rsCheck("MEMBER_ID"))

I suppose this should be
if rsCheck("M_STATUS") = 1 and ((strAuthType="db" and fPassword=rsCheck("M_PASSWORD")) ?

Go to Top of Page

work mule
Senior Member

USA
1358 Posts

Posted - 20 July 2003 :  04:09:06  Show Profile
Oops, yes that is correct.

Due to the modifications I've been making, I had to refer back to a copy of the original code to make sure the index didn't already exist (and I had accidentally removed it on mine) and that the functions were still similiar. After I checked it out, I modified the original copy instead of copying and pasting my code.

Thanks for catching that.

Edited by - work mule on 20 July 2003 04:13:35
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 20 July 2003 :  04:20:22  Show Profile
Your site is really a nice one.

btw, I just got an error by trying to search your forum.
http://www.trains.com/community/forum/search.asp?search=test&forum=91&mode=DoIt
Go to Top of Page

work mule
Senior Member

USA
1358 Posts

Posted - 20 July 2003 :  10:29:44  Show Profile
I really hope these two mistakes in modifying the original code doesn't distract from the original intention. While it may not have an impact on sites with a small userbase and low number of concurrent users, I think it is really important for the sites which have a larger userbase and/or a high number of concurrent users.

- - - - - - - - - - - -

bjlt, thanks again for catching that.

That error on the search page was the result of trying to make a correction and get it done before the network engineers took down the local network Friday night to do some maintenance.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 20 July 2003 :  12:06:52  Show Profile  Send ruirib a Yahoo! Message
Well workmule I think your analysis is a very interesting one. The Snitz code has been improved quite a lot from 3.3.0x to 3.4.x, in terms of server load, and it looks like the info you gathered can clearly be used to improve it further, IMO. Nice work :).


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 1.51 seconds. Powered By: Snitz Forums 2000 Version 3.4.07