Hi, we've been ahving some problems with our hppt server running out of memory for a while. I've found a bunch of threads with the same problem in this forum, but the suggestions made there doesn't seem to work. So far I've tried to increase the _RTCSPCB, _RTCS_msgpool and RTCS_socket parameters according to other answers and that has done very little. I've also reduced the stack usage of all of our tasks and this has helped some in that it takes longer to run out of RAM, but we still run out of RAM eventually. My most resent change was to reduce HTTPSRV_SESSION_STACK_SIZE from 3000 to 1500 but that didn't seem to have any effect.
Right now when we start the application the RAM usage is about 54K out of 120K available. If I open a web browser and connect to our products http server the RAM usage instantly rises to 66K. If I click around on our different web pages the ram usage is unaffected. But if I press F5 to refresh the page a few times with about 1 second interval the RAM usage rises to 80K. If I keep on pressing F5 on the web page eventually the RAM usage will reach 120K and the tcp/ip task will report out of memory error. To me it seems unreasonable that the http server should occupy more than half of our total RAM size of 128K.
The httpsrv example get free the memory that had used, but when you are pressing F5, the refresh is so fast, the browser opens a new session, the code identifies the sessions that are not using and closes. So, be sure to free the memory, and close all the session that you are not using.
MQX is limited, is embedded, remember you should care the memory.
Hope it helps
Yes, the RTCS stack closes all the sessions that you are not using, but be sure that the CPU has enough time for closing the session.
Check if the sessions still have some process executing, if it is, the stack can’t closed and consume memory.
Let me know your findings
So, I finally had some time to test this some more. The problem as you said seem to be that a new session is created everytime the refresh button is pressed. So everytime the user refreshes their browser I guess a new socket gets opened for the new session and then also a new task is started that uses 2kb stack (3kb default). So when the user keeps pressing F5 the memory eventually runs out and the http server stops responding for a while. I digged around in the header files of the RTCS and found this:
#define HTTPSRVCFG_SES_TO (20000)
I assume that is the timeout for a http session. In this case it would mean that the timeout time is 20 seconds. So am I right in assuming that it takes 20 seconds of inactivity for a session to close and then return the stack size it was using? I can refresh the browser a ton of times in 20 seconds. So would it be wise to lower that value significantly to make sure only a few new sessions gets created before the older ones timeout? Or would this have considerable drawbacks?
No, I've not found a solution. And I take the lack of response from NXP(Freescale) as a sign that they know about the problem, but don't want to do anything about it
I am trying to replicate the issue and find a solution that can help you. I ran the http server and I didn´t find any problem with the example.
I monitored the task summary and the socket summary and all are working fine.
Could you please provide your example code and your html file?
Like I've said before, this problem isn't only in my own programs. I found the exact same problem in the MQX RTCS httpsrv example. If I keep pressing F5 to update the browser window the RAM usage goues up. I see this by checking MQX -> Lightweight Memory Blocks. As long as I just click around on the page the the value at Higest stays the same, but as soon as I start pressing F5 or the refresh button in my browser a few times the Highest number goes up.
I have trying to replicate the issue with the MQX RTCS httpsrv example and I saw in Checking MQXàLightweight Memory Blocks that the RAM usage goes up, but it doesn´t mean that you are out of memory.
The value is a RAM memory watermark, it is the memory value that the uC did use and then free the memory, you calculate the free memory, and if you compare with the highest value, you could check that the values are not the same, for example
Highest: 0x2000acf3 (105.0k, 83%).
Free: 0x1184 + 0xFFEC = 0x11170 = 70k
The free values are in the bottom of the Lightweight Memory Blocks.
Then 125k – 70k you have 55k of usage memory, the 83 % or 105k is the maximum value of memory in a work stress.
Do you have the same report out of memory error in the httpsrv example? Or do you see only the RAM goes up?
Hope It helps
I know that it's the highest ammount of memory used, and not the current usage. But if it ever reaches 100 % (which it's done sometimes for me) then I don't think it's a good sign. What if it needed to allocate more memory while at 100 %, then there would be none left to use? And I still don't understand why the behaviour is different from when clicking on the same page over and over again versus using the refresh button. They should have the same effect.
I ran this test with http demo and it worked fine. I assume you are using CGI, right? Probably some resources used by the CGI are not being released and new resources are used each time the browser refreshes. See also the number and the status of the opened sockets. You can see this in menu MQX > Sockets. It is possible that the sockets are keeping alive when they are no longer used.
Please let me know your findings,
Yes, we use CGI but the memory problem doesn't seem to arise as long as we just click on the same web page over and over again from our menu. It only happens when we use F5 to refresh the browser. Is there a difference in the MQX RTCS stack for how menu navigation clicks and refreshes are handled?
I've been using Firefox for the most part but it also happens in Explorer and Chrome. I did some more tests to give you a better picture of the problem. First I tested with our application. I start the application, go to the web page in the browser and check the max RAM usage in the program. Then I click on the same menu button (with my mouse) over and over again for about 10 seconds for maybe a total of 20 times. I then check the RAM usage again and it is the same as before. Then I try to update the same page over and over again with the same speed but this time I use F5 instead. The result were this:
Firefox: 81 % -> 96 %
Chrome: 78 % -> 83 %
I then did the same test with the MQX 4.2 httpsrv example on our TWR kit and got the same behaviour. Just clicking on menu buttons with my mouse doesn't increase the max RAM usage, but when I use F5 to refresh the page the RAM usage goes up. The result looked like this:
Firefox: 51 % -> 76 %
Chrome: 52 % -> 65 %
No, clicking the reload page button with the mouse would be the same as pressing F5. I mean that we have several web pages in our web server and they are organized in a menu with one button for every page. It's that button I keep pressing. It looks like this in our hmtl code