Using too Many Server Resources??? (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


bigtime -> Using too Many Server Resources??? (8/31/2005 16:28:13)

I received this message from my webhost. I am sure I can ask the web host to translate it to laymans terms, but can anyone here guide me where I am going wrong. I am using an access database. I don't get a whole lot of hits. I spooky dieted all of my code. I do record movements of visitors to an access database (about 28,000 records). Is there something I might be missing or do I need to post the code from a typical page for more answers?

Thanks in advance.

MESSAGE:
Your asp/aspx applications are now running properly. This issue with intermittent display of asp/aspx pages is usually related to the application pool being recycled. The application pool is recycled every 12 hours on our shared windows plans. The reason the application pool failed is that an application on your site is using too many server resources and was shut down as to not harm other applications on the server. You may wish to optimize you code to run with a higher efficiency to avoid these issues in the future.




rdouglass -> RE: Using too Many Server Resources??? (9/1/2005 15:27:04)

Are you using all DRW's on your site? Do you have any ASP pasges doing regular DB calls? Many times those DB connections aren't closed properly and that'll keep those server resources in use.

A quick way to check is at the bottom of an ASP page in question is to put something like this:

<%conntemp.close%>

substituting conntemp with your db connection name. If the page does NOT error, you have left at least 1 open database connection. If it errors, the connection has been closed properly. You'll need to do that for each different DB connection if you use more than 1 per page.

AT least that's how I check 'em.

EDIT: I'd look very closely at that connection that updates your visitor's movements. [;)]




bigtime -> RE: Using too Many Server Resources??? (9/1/2005 21:59:23)

Thanks RDouglass..I will check each of the web pages.

Could I trouble you to check this code from the redirect page that writes to the database before redirecting? This code is supposed to write to a database when a user clicks on a link in my site, then redirect to the site they clicked on. I am also trying to filter out any web bots.

I'm still new to asp and I know there are a lot of <% and %> in here. I hope each one of these is not a new trip to the server. Feel free to rip it apart for optimization, as I am still learning.


<% Request.QueryString("VendorHomepage")
   URL=Request.QueryString("VendorHomepage")%>

<%
Dim adCmdText
Dim sDatabase
Dim oFSO
Dim oConnection
Dim sSQL
Dim oCommand
Dim rsResults
Dim sConnection

If LEFT(request.servervariables("REMOTE_ADDR"),6)="66.196" Then
    Response.Redirect URL
End If    

If LEFT(request.servervariables("REMOTE_ADDR"),6)="68.142" Then
    Response.Redirect URL
End If    

If LEFT(request.servervariables("REMOTE_ADDR"),7)="216.117" Then
    Response.Redirect URL
End If   

If LEFT(request.servervariables("REMOTE_ADDR"),5)="65.54" Then
    Response.Redirect URL
End If    

If LEFT(request.servervariables("REMOTE_ADDR"),7)="212.227" Then
    Response.Redirect URL
End If
 

If Not Response.IsClientConnected Then
  Response.End
Else
   On Error Resume Next
  
  sDatabase=Server.Mappath("fpdb/main.mdb")

Set oFSO = CreateObject("Scripting.FileSystemObject")

  If (oFSO.FileExists(sDatabase)) Then
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Mode = 3
    sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"
    sConnection = sConnection & "Data Source=" & sDatabase & ";"
    oConnection.Open sConnection

    sSQL = "SELECT * FROM redirect WHERE ID=0"
  
    
    Set oCommand = Server.CreateObject("ADODB.Command")
    Set oCommand.ActiveConnection = oConnection
    oCommand.CommandText = sSQL
    oCommand.CommandType = 1

    Set rsResults = Server.CreateObject("ADODB.Recordset")
    rsResults.Open oCommand,,1,3
    Set oCommand = Nothing

    With rsResults        
      .AddNew
      .Fields("URL").Value=Request.QueryString("VendorHomepage")
      .Fields("IP_Address").Value=Request.ServerVariables("REMOTE_HOST")
      .Fields("Timestamp").Value=dateadd("H",+3,now())
      .Update
      .Close
    End With
    Set rsResults = Nothing
    oConnection.Close
    Set oConnection=Nothing
  End If
  Set oFSO = Nothing
End If
%>
<%
Response.Redirect URL
%>






J-man -> RE: Using too Many Server Resources??? (9/2/2005 0:50:19)

Thats some tight code but many adjustment can be made like having three dimensional dynamic array , storing '6' and '66.196' and the 'Response.Redirect URL' OR using the ASP Case statment instead of all those Ifs
*example: http://www.w3schools.com/vbscript/tryit.asp?filename=vbdemo_selectcase

piIf LEFT(request.servervariables("REMOTE_ADDR"),6)="66.196" Then
    Response.Redirect URL
End If






rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 9:35:58)

I think you can do something here. How about something like this:

If Not Response.IsClientConnected Then
  Response.End
Else
   On Error Resume Next
  
    sDatabase=Server.Mappath("fpdb/main.mdb")
    sSQL = "INSERT INTO redirect (URL,IP_Address,Timestamp) VALUES ('" & Request.QueryString("VendorHomepage") & "','" & Request.QueryString("REMOTE_HOST") & "',#" & dateadd("H",+3,now()) & "#)"

    Set oConnection = CreateObject("ADODB.Connection")
    sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/main.mdb")
    oConnection.Open sConnection
    oConnection.close
    Set oConnection=Nothing

End If


...for the database writes? I say this 'cause I don't really understand why you have an FSO in there to check for the DB file existence. Does it change regularly? If so, have it check at first entry or even apllication launch, not every time you write a new log item. At least IMO.

Also, why the 2 different recordset connections? Aren't you just writing a little record? If you need to identify the user, how 'bout a quick login and then use a cookie or session variable for a value? To me it seems like a lot of extra db hashing.

Lastely, yes I'd consider the redirect section a candidate for a CASE statement. Maybe something like:

<%
IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

CASE (myTempArray(0) & "." & myTempArray(1))

CASE "66.196","68.142"",216.117","65.54","212.227"
Response.redirect(url)
END SELECT
END IF%>

I'm guessing what you want is to not record any activity from those subnets. By "split"ting the IP, we don't have to worry about string length and all those different IF...THEN's. That might be some of the performance issue but I think the first one is more important.

SO if it were me, I'd probably attempt to reduce the code down to something like this:

<% Request.QueryString("VendorHomepage")
   URL=Request.QueryString("VendorHomepage")%>

<%
Dim adCmdText
Dim sDatabase
Dim oFSO
Dim oConnection
Dim sSQL
Dim oCommand
Dim rsResults
Dim sConnection

IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

CASE (myTempArray(0) & "." & myTempArray(1))

CASE "66.196","68.142"",216.117","65.54","212.227"
Response.redirect(url)
END SELECT
END IF
If Not Response.IsClientConnected Then
  Response.End
Else
   On Error Resume Next
  
    sDatabase=Server.Mappath("fpdb/main.mdb")
    sSQL = "INSERT INTO redirect (URL,IP_Address,Timestamp) VALUES ('" & Request.QueryString("VendorHomepage") & "','" & Request.QueryString("REMOTE_HOST") & "',#" & dateadd("H",+3,now()) & "#)"

    Set oConnection = CreateObject("ADODB.Connection")
    sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/main.mdb")
    oConnection.Open sConnection
    oConnection.close
    Set oConnection=Nothing

End If

Response.Redirect URL
%>


One biggie IMO is to be sure and do things only when necessary. If you need to check for the existence of the DB file, do it once per user session at maximum. Definitely not everytime you access the db. If you *have* to check every time, I'd suggest Access is *not* the solution for you.[;)]

Another one is don't use the recordset object to write to the DB. Build your SQL string and then open run the sql and close the session. Using Addnew - Fields - Update - Close IMO is just too much overhead for these simple writes.

That any help?




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 9:55:46)

Thanks RDouglass

I used your code but I am getting an error on this

/redirect.asp, line 18

CASE (myTempArray(0) & "." & myTempArray(1))
^




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 10:01:12)

quote:

IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

CASE (myTempArray(0) & "." & myTempArray(1))


OOPS! [X(]

...IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

SELECT CASE

CASE (myTempArray(0) & "." & myTempArray(1))
...

Sorry 'bout that.[8|]




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 10:11:08)

Thanks RDouglass,
Minor issue though
Using this code
IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

SELECT CASE

CASE (myTempArray(0) & "." & myTempArray(1))



I get This

/redirect.asp, line 18

SELECT CASE
-----------^


Using this code:

IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

SELECT CASE (myTempArray(0) & "." & myTempArray(1))



It hangs on the redirect page.




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 10:16:23)

quote:

It hangs on the redirect page.


Sorry 'bout that code error. Was up 'till 3 AM and I haven't had my 5th cup of coffee yet this AM. [;)]

Can you elaborate more on "hangs"? Is there any indication of a busy browser (hourglass, animated Windows icon, etc.)

Can you do something like this for debugging?

...
CASE "66.196","68.142"",216.117","65.54","212.227"
Response.write(url)
Response.end

Response.redirect(url)
...

Just to see what 'url' is?




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 10:26:05)

LOL...I guess it would help if I put the Request.Querystring and URL= in there first hugh?

I missed that Part.

I just tried that and it works.

Thanks a whole bunch. But now it is not writing to the database.




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 10:28:18)

quote:

I missed that Part.


Coffe pot empty too 'eh? [:D]




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 10:30:02)

Yes it is...LOL


But now it is not writing to the database. Is there something missing here?
 sSQL = "INSERT INTO redirect (URL,IP_Address,Timestamp) VALUES ('" & Request.QueryString("VendorHomepage") & "','" & Request.QueryString("REMOTE_HOST") & "',#" & dateadd("H",+3,now()) & "#)"







rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 10:45:00)

quote:

sSQL = "SELECT * FROM redirect WHERE ID=0"


What is it you were doing here? Maybe I didn't include something in the revised code?




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 10:49:51)

I dunno...this was plagerized code :)




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 10:55:43)

quote:

CASE "66.196","68.142"",216.117","65.54","212.227"


Are you in any of those IP subnets? IOW, try putting this before the DB code:

Response.write("request.servervariables("REMOTE_HOST"))
Response.end

just to be sure you're not in any of those subnets. If you are, you'll never get to the DB write code.

Also, what is going on here? Has the condition been met?

If Not Response.IsClientConnected Then
  Response.End
Else




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 11:03:06)

Not in any of those subnets.

I'm not really sure what the NOT REPONSE code is. As I sadiad, I am a newbie and this is plagerized code.

I removed that other code and it is still not writing to the database.




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 13:07:57)

quote:

'" & Request.QueryString("REMOTE_HOST") & "'


Did you see my screwup here? [:'(]

'" & Request.servervariables("REMOTE_HOST") & "'

That work any better?




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 13:32:46)

Yes i caught this one about an hour ago and changed it. Still is not writing to the database. I also changed Timestamp to [Timestamp]. I am checking ' & " as we speak also. Any other ideas?






rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 13:41:27)

I had one but I wanted to check the typo first.

Put this code at the top of the page just after the <body> tag line.

<%
SUB CloseAll
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
END SUB

myDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/main.mdb"
mySQL = "SELECT * FROM redirect"

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
If rstemp.eof then
response.write "No records matched<br>"
Call CloseAll
response.end
else
alldata=rstemp.getrows
Call CloseAll
Response.write("First row, first field:" & alldata(0,0) & "<br>")
end if
%>

What is the output of that script?




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 13:51:25)

After adding the ) after .mdb

I get this error
Unterminated string constant

/redirect.asp, line 22

Response.write("First row, first field:" & alldata(0,0) & "<br>
---------------------------------------------------------------^




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 13:53:23)

quote:

Response.write("First row, first field:" & alldata(0,0) & "<br>")


That's what the line should read. Did you copy and paste straight from the forum? Many times you have to paste it into notepad first. Edit it by hand if necessary.




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 13:55:24)

Yes I seen that and I changed it. It redirects to the web page but does not write to the file.

So it is redirecting right to the web page.




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 13:57:06)

Directly after that response.write line put a:

Response.end

That will stop everything and display the result.




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 14:00:10)

output is

First row, first field:7




rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 14:08:17)

OK. Bear with me now...[;)]

Replace the code from that line like this:

Response.write("First row, first field:" & alldata(0,0) & "<br>")


to this:

FOR i = 0 TO ubound(alldata,1)
Response.write("First row, first field:" & alldata(i,0) & "<br>")
NEXT


(notice I changed the first '0' to an 'i'.)

What does that return?




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 14:12:16)

First row, first field:7
First row, first field:http://www.epartysite.com
First row, first field:209.60.96.9
First row, first field:10/20/2004 8:09:11 PM




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 14:39:32)

I had to do some recoding but got this to work:


<%
Request.QueryString("VendorHomepage")
   URL=Request.QueryString("VendorHomepage")


IF request.servervariables("REMOTE_ADDR") > "" THEN
myTempArray = split(request.servervariables("REMOTE_ADDR"),".")

SELECT CASE (myTempArray(0) & "." & myTempArray(1))

CASE "66.196","68.142"",216.117","65.54","212.227"
Response.redirect(url)
END SELECT
END IF


Dim myConnString
	Dim myConnection
	Dim mySQL

	
myConnString = Application("Main_ConnectionString")
Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Open myConnString
	
	
	mySQL= "INSERT INTO Redirect "
                mySQL= mySQL & "(URL,IP_Address,[Timestamp]) "
	mySQL= mySQL & "VALUES ('" & Request.QueryString("VendorHomepage") & "','" 
                mySQL= mySQL & Request.servervariables("REMOTE_HOST") & "','"
               mySQL= mySQL & dateadd("H",+3,now()) & "')"
    
myConnection.Execute mySQL
	myConnection.Close
	Set myConnection = Nothing
  
 
    
Response.Redirect URL




It worked but will it work for the intial question on excess server usage.

Thanks for all your help RDouglass....I think I need a beer after this one.

It's weekend Mode.





rdouglass -> RE: Using too Many Server Resources??? (9/2/2005 14:56:12)

quote:

It worked but will it work for the intial question on excess server usage.


It should help. We've removed the (unnecessary IMO) FSO item (a big resource hog) and cut the DB connections in half and did the write in 1 server call vs. 3.

To me that should be significant. Around 1/8 the processing overhead.




bigtime -> RE: Using too Many Server Resources??? (9/2/2005 15:13:54)

As I said before the original code I plagerized from somewhere else. The newest code I plagerized from this forum someplace a few months ago:) As a newbie, I have to learn (hack) from somewhere.

At least the processing resources are decreased and I should not get any more nastygrams or cutoffs from the webhost.

Thanks again for all your help.






Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.109375