Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to fix issue with allocated memory in Web Server



Permlink Replies: 7 - Last Post: Oct 20, 2017 7:56 AM Last Post By: Eitan Arbel
Roman Bay

Posts: 16
Registered: 6/14/13
How to fix issue with allocated memory in Web Server
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 11, 2017 5:47 AM
We have Web Server that base on IntraWeb (v 14.1.2). Also we are using CGDevTools components.

Our Web Server gives possibility to open 13 pages.

One mouth ago we have changed our approach of web pages creating.
Before the changes we had some code to create new pages and remove old, like this:
var
lOldActiveForm: TComponent;

lOldActiveForm := WebApplication.ActiveForm;
Result := AFormClass.Create(WebApplication);
WebApplication.ReleaseForm(lOldActiveForm);

We modify it a little. So now we don’t remove old pages just creating new one if it not exists
Result := FindForm(AFormClass); {find form in Forms list}
if Result = nil then
Result := AFormClass.Create(WebApplication);

But after this changes we got memory issue. If we are using 20-30 active sessions then allocated memory for the Web Server will be increase very quickly.
For example our server starts from 25MB and every new session adds approximately 35MB (provided that the user opens almost all pages in this session).

When allocated memory is more them 300MB or sometimes 200MB then we get a lot "Access violation" errors and
"Error reading imgContextMenuIconCOLREG1X2.Picture.Picture.Data: Access violation at address 0040868B in module 'TDWebSrv.exe'. Write of address 00000000".
(please see Exception log files [https://ufile.io/lj9p8]).

Question is:
Do anybody have some recommendation about correct way for page creation? Is it ok that we don't remove page if user go from one page to another?

Edited by: Roman Bay on Oct 11, 2017 5:47 AM

Edited by: Roman Bay on Oct 11, 2017 5:50 AM
Chad Hower

Posts: 613
Registered: 3/2/07
Re: How to fix issue with allocated memory in Web Server [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 11, 2017 6:46 AM   in response to: Roman Bay in response to: Roman Bay
On 10/11/2017 8:53 AM, Roman Bay wrote:
We modify it a little. So now we don’t remove old pages just creating new one if it not exists
Result := FindForm(AFormClass); {find form in Forms list}
if Result = nil then
Result := AFormClass.Create(WebApplication);

But after this changes we got memory issue. If we are using 20-30 active sessions then allocated memory for the Web

This is probably the result of leaving your forms in memory. Forms by
themselves are not heavy but if you are opening and leaving a lot of
state open, DB connections etc it will add up.
Roman Bay

Posts: 16
Registered: 6/14/13
Re: How to fix issue with allocated memory in Web Server [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 12:49 AM   in response to: Chad Hower in response to: Chad Hower
Chad Hower wrote:

This is probably the result of leaving your forms in memory. Forms by
themselves are not heavy but if you are opening and leaving a lot of
state open, DB connections etc it will add up.

Almost all our pages have TIWCGJQGrid controls and in most cases grids contain minimum 1 column with buttons, images etc..

But I think even if we will use only one page and 300 active sessions it can be problem because Web Server will use more then 500MB.
Is it normal situation for IntraWeb or maybe we are doing something wrong and Web Server shouldn't use so much memory?
Chad Hower

Posts: 613
Registered: 3/2/07
Re: How to fix issue with allocated memory in Web Server [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 5:44 AM   in response to: Roman Bay in response to: Roman Bay
On 10/12/2017 3:49 AM, Roman Bay wrote:
But I think even if we will use only one page and 300 active sessions
it can be problem because Web Server will use more then 500MB. Is it
normal situation for IntraWeb or maybe we are doing something wrong
and Web Server shouldn't use so much memory?

Memory usage is totally dependent on your code. A bare IntraWeb session
does not consume much.

So memory usage totally depends on your design and needs.
Jose Nilton Pace


Posts: 122
Registered: 5/15/98
Re: How to fix issue with allocated memory in Web Server
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 11, 2017 11:56 AM   in response to: Roman Bay in response to: Roman Bay
Roman, just an idea ok. Maybe you use a SetURL to try to solve this. In every Form try the code above and use it in href="users.html"
initialization
  TIWF_Users.SetURL('/', 'users.html');
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: How to fix issue with allocated memory in Web Server
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2017 1:23 AM   in response to: Roman Bay in response to: Roman Bay
Hi,

About your code:

1) I don't recognize FindForm() method. I guess this is your code, right? IWApplication already has methods for that, you don't need to reinvent the wheel.

IWApplication has:

 
// Returns a form of the same class name if an instance already exists in this session
function TIWApplication.FindFormByClassName(const AFormClassName: string): TComponent;
 
// Returns a form of the same name if an instance already exists in this session
function TIWApplication.FindFormByName(const AFormName: string): TComponent;


2) Don't call WebApplication.ReleaseForm(). The preferred way to release a form is calling its own Release() method, not WebApplication's. So you should do this:

var
  lOldActiveForm: TComponent;
  lNewForm: TIWForm;
begin
  // Release old active form
  lOldActiveForm := WebApplication.ActiveForm;
  if Assigned(lOldActiveForm) then
    TIWForm(lOldActiveForm).Release;
  // show or create new form
  lNewForm := WebApplication.FindFormByClassName(AFormClass.ClassName) as TIWForm;
  if not Assigned(lNewForm) then
    lNewForm := AFormClass.Create(WebApplication);
  lNewForm.Show;


3) About memory consumption: 300 Mb is very little. You should be able to use more than 2 Gb in any IW application compiled in 32 bits. As 64 bits, the limit is the installed memory. These AV errors in general are caused by errors in user code, and can't be due to memory usage.
I'll have a look at the exception log files and maybe I can find something else there. I'll keep you informed.

Roman Bay wrote:
We have Web Server that base on IntraWeb (v 14.1.2). Also we are using CGDevTools components.

Our Web Server gives possibility to open 13 pages.

One mouth ago we have changed our approach of web pages creating.
Before the changes we had some code to create new pages and remove old, like this:
var
lOldActiveForm: TComponent;

lOldActiveForm := WebApplication.ActiveForm;
Result := AFormClass.Create(WebApplication);
WebApplication.ReleaseForm(lOldActiveForm);

We modify it a little. So now we don’t remove old pages just creating new one if it not exists
Result := FindForm(AFormClass); {find form in Forms list}
if Result = nil then
Result := AFormClass.Create(WebApplication);

But after this changes we got memory issue. If we are using 20-30 active sessions then allocated memory for the Web Server will be increase very quickly.
For example our server starts from 25MB and every new session adds approximately 35MB (provided that the user opens almost all pages in this session).

When allocated memory is more them 300MB or sometimes 200MB then we get a lot "Access violation" errors and
"Error reading imgContextMenuIconCOLREG1X2.Picture.Picture.Data: Access violation at address 0040868B in module 'TDWebSrv.exe'. Write of address 00000000".
(please see Exception log files [https://ufile.io/lj9p8]).

Question is:
Do anybody have some recommendation about correct way for page creation? Is it ok that we don't remove page if user go from one page to another?

Edited by: Roman Bay on Oct 11, 2017 5:47 AM

Edited by: Roman Bay on Oct 11, 2017 5:50 AM
Roman Bay

Posts: 16
Registered: 6/14/13
Re: How to fix issue with allocated memory in Web Server
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2017 2:43 AM   in response to: Alexandre Machado in response to: Alexandre Machado
1) I don't recognize FindForm() method. I guess this is your code, right? IWApplication already has methods for that, you don't need to reinvent the wheel.

Thank you for the recommendation. We will try to use FindFormByClassName instead own FindForm().

3) About memory consumption: 300 Mb is very little. You should be able to use more than 2 Gb in any IW application compiled in 32 bits. As 64 bits, the limit is the installed memory. These AV errors in general are caused by errors in user code, and can't be due to memory usage.
I'll have a look at the exception log files and maybe I can find something else there. I'll keep you informed.

We have fixed the issue. Problem was that we were using LoadFromFile methods to load pictures to controls (buttons, images). The LoadFromFile was used for a lot places including buttons and images controls that we are using for the grids.
      imgPicture.Picture.Picture.LoadFromFile(WebFolderImages24 + '036.png'); 
      btnOrderAdd.JQButtonOptions.Icons.PrimaryPicture.Picture.LoadFromFile(WebFolderImages24 + '127.png');
 

It was changed to:
      imgPicture.Picture.Url := HTMLWebFolderImages24 + '036.png';
      btnOrderAdd.JQButtonOptions.Icons.PrimaryPicture.Url := HTMLWebFolderImages24 + '127.png';


After the changes we had possibility to overload WebServer to more than 1GB memory consumption and everything works ok.

But still we are trying to find out why memory consumption for one page is approximately 3-6 MB. Because even if we closed all datasets for some page it doesn't fix it.
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: How to fix issue with allocated memory in Web Server
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2017 4:51 AM   in response to: Roman Bay in response to: Roman Bay
to add to what everybody said here...
creating the forms without releasing them will just add up and up to the memory consumption.

if you just need to release the ActiveForm, then you can use this very efficient line of code :
TIWAppForm(WebApplication.ActiveForm).Release;

and to create the form i use :

With AFormClass.Create(WebApplication) Do Begin
  //what ever you want to add to the creation
  //...
  Show;
End


so, to dynamically release and create your forms (if i understand it correctly - for your menu) :
procedure TYourMenu.Move(AFormClass : TIWAppFormClass);
begin
  // Release the current form
  TIWAppForm(WebApplication.ActiveForm).Release;
 
  // Create the next form
  With AFormClass.Create(WebApplication) Do Begin
  //what ever you want to add to the creation
  //...
    Show;
  End;
end;


which is a very common way for menus, and is used also in some iw demos
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02