Web Services Leaking memory and high cpu usage

Hello, i have built a web service using Xojo HandleSpecialurl event in order to accept requests and store data to a database (mysql).
The service accepts around 100.000 requests day. But here is the problem:

When i start the service the memory being used is about 8MB but as the requests keep coming the memory keeps increasing and somewhere around 11MB the cpu is around 8-11% (which means that on core works at 90%, because there are 8 cores on the machine). This is happening until the memory used by the service reaches the 25MB, thereby the service is almost not responding.

I have checked many times for Circular References and whenever a property is being passed as a parameter or referenced outside the object i use weakref but it does not seem to solve the problem. Also, i clear every array and every Dictionary that i use.

Any ideas where to look ?

First thing I’d check is to see how much free memory is available on the system. If your app running at 25MB takes all available memory, that could certainly be the problem.

Another possibility though… It could just be that the app has reached its limit of simultaneous connections.

If your app is built as Standalone, you can increase the number of allowed connections by setting the

--maxsockets command line property.

Hello Greg and thank you for your response.

No, the memory available on the system is about 15GB free (total is 32GB). So i suppose this is not an issue.

I doubled the value of maxsockets (maxsecuresockets in my case), but i dint notice any difference. Is it normal that the service keeps increasing the amount of memory and cpu draining ?

No. If the memory is not released 3 minutes after a user leaves the app, I would consider that a memory leak.

While I’m not saying it can’t happen, I’d be very surprised if it’s the Xojo framework that’s causing this problem as they’d be affecting everyone that uses the product.

Try something for me. Build a completely empty web project and put it up there. Access it from several browsers and platforms and see if you get the similar results ( runaway memory and cpu consumption)

[quote=213702:@Greg O’Lone]No. If the memory is not released 3 minutes after a user leaves the app, I would consider that a memory leak.

While I’m not saying it can’t happen, I’d be very surprised if it’s the Xojo framework that’s causing this problem as they’d be affecting everyone that uses the product.

Try something for me. Build a completely empty web project and put it up there. Access it from several browsers and platforms and see if you get the similar results ( runaway memory and cpu consumption)[/quote]
Thank you again, ill try what you suggest and let you know.
Also, the application is only accepting requests via handlespecialUrl and respond to them. No users are able to access it.

Ok. Without sessions involved, that certainly narrows it down. That said, the code path for HandleSpecialUrl is identical to a session request up to the point when the event is fired and a in a quick code review I don’t see a candidate for a leak.

Best thing you could do if you still think it’s in our framework is to replicate this in a small project and file a bug report do we an see it in action.

Hello again Greg, so here is what i tried.

I created a very simple Web Project, and in the App.HandleSpecialUrl added some code to parse requests with the following code

[code]
Call logreq

dim inpData as new Dictionary
if Request.Entity <> “” then
requestParser(Request.Entity, inpData)
elseif Request.QueryString <> “” then
requestParser(Request.QueryString, inpData)
else
return false
end if

dim jsonIt as JSONItem = new JSONItem( inpData.Value(“data”))
dim retval as string= jsonIt.Child(0).Value(“ID”)
Request.Print retval

return true[/code]

*The function logreq prints the id on the terminal

The request was like

http://mydomain.com:8080/api/?data=[{“ID”:15}]

and return the id to the caller

  Request.Print  retval

I have also created another project in order to make requests. The application takes as input the domain, the data and the number of requests. At the beginning everything was fine, i was doing the request and get the response. But when i tried to make about 30 requests simultaneously i noticed that the service wasn’t able to handle all of them as it did not print all of them on terminal. As a result i wasn’t able to get all the responses too. After some time (around 1.5 mins) the service printed some more requests on the terminal but the whole procedure was very slow.

Another thing i noticed was that the number of threads was increasing from 1-2 to 7-8 during the requests.

Test were made on Windows 8.1 64bit Operating System, 8gb memory, intel i-5 @ 3GHz

Please put all of this including your sample project into a Feedback bug report and we’ll take a look at it.

FeedBack Case:41187 - handlespecialurl Not Responding Misses Requests