Recent

Author Topic: [SOLVED] HTTPMethod in Synapse is slow and freezes program operation momentarily  (Read 17947 times)

newman

  • Jr. Member
  • **
  • Posts: 75
Hi,

I have installed Apache2 server on my computer (OS: Ubuntu 10.04), with PHP and MySqlite support.

I am using this function below to send HTTP post method to a PHP file (that resides in a site also in my computer), I am using synapse library.  

Code: [Select]
function PostInetCommand(cPostData:string):string;
var
  HTTP: THTTPSend;
  l: tstringlist;
  cResponse:string;
  b:boolean;
begin
  HTTP := THTTPSend.Create;
  l := TStringList.Create;

  try
    if not HTTP.HTTPMethod('POST',cPostData) then
      begin
        Result:= 'Error';
      end
    else
      begin
        l.loadfromstream(Http.Document);
        Result:= l.Text;
     end;
  finally
    HTTP.Free;
    l.free;
  end;
end;


I find that the program operation freezes momentarily and the response from PHP file is very slow (at least 3 -4 seconds), whereas the same post operation done from a browser is instantaneous.

Please explain why this is happening ?? also how can I improve the performance.

PS: Sorry if I could not make myself clear as I am new to network programming.


thanks
nm
« Last Edit: February 01, 2011, 09:35:46 am by newman »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #1 on: January 31, 2011, 01:43:38 pm »
Mine here is fast, could you make sure that it's faster with php?

Silvio Clécio

  • Guest
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #2 on: January 31, 2011, 01:54:47 pm »
Hi newman,

Use thread, see demos with threads in:

http://code.google.com/p/lazsolutions/

Good luck. ;)

newman

  • Jr. Member
  • **
  • Posts: 75
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #3 on: January 31, 2011, 04:28:14 pm »
Mine here is fast, could you make sure that it's faster with php?

I am using PHP..and its not fast...

Just for my information how fast should the response from the server be ?

Hi newman,

Use thread, see demos with threads in:

http://code.google.com/p/lazsolutions/

Good luck. ;)

thanks for the link, I downloaded the lazsolutions zip file, but threads are a bit steep for me..but I am working on it...
« Last Edit: January 31, 2011, 04:34:34 pm by newman »

Silvio Clécio

  • Guest
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #4 on: January 31, 2011, 04:51:48 pm »
Hi newman,

But isn't hardly, it's very easy, please see this:

http://code.google.com/p/lazarus-br/source/browse/trunk/misc/BeginThread/MainFrm.pas

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #5 on: January 31, 2011, 05:08:07 pm »
But isn't hardly, it's very easy, please see this:

How is access to MainForm.DisplayLabel.Caption synchronized in this example?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #6 on: January 31, 2011, 05:22:28 pm »
Quote
I am using PHP..and its not fast...
Then it's not HTTPMethod problem, it's the processing of POST (in your PHP file) that's slow.
Quote
Just for my information how fast should the response from the server be ?
Too many things to consider before saying something about this. Nevertheless, at localhost, if the request is simple (i.e. no complicated data processing) it should be in a blink of an eye.

Silvio Clécio

  • Guest
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #7 on: January 31, 2011, 05:26:45 pm »
Hi theo,

Sorry but I do not understand the question. :-[ (My English is not very good)

(...)
var
  MainForm: TMainForm;

.
.
.

procedure HeavyProcess;
var
  I: Integer = 0;
begin
  while I < 1000 do
  begin
    MainForm.DisplayLabel.Caption := IntToStr(I);
(...)

Other situation:
http://code.google.com/p/lazsolutions/source/browse/trunk/Demos/LSSMTPSend/Thread/MainFrm.pas#78

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #8 on: January 31, 2011, 05:59:45 pm »
Hi theo,
Sorry but I do not understand the question. :-[ (My English is not very good)

It looks like this code is updating MainForm.DisplayLabel.Caption from within a separate thread without synchronizing with the main thread.  Afaik this will crash sooner or later.

Silvio Clécio

  • Guest
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #9 on: January 31, 2011, 08:58:26 pm »
Hi theo,

How can I fix this without using global variable?

I have a solution to use in this demo, but using a global variable.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #10 on: January 31, 2011, 09:46:15 pm »
How can I fix this without using global variable?

I never use BeginThread(..) and friends, always TThread class.

You can see an example here (PT for you  ;) )
http://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial/pt#A_classe_TThread

See: Synchronize(@Showstatus);

Silvio Clécio

  • Guest
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #11 on: January 31, 2011, 10:13:29 pm »
Hm..., I always forever use TThread class too, but I avoided because this class is with memory leaks in Lazarus:

http://lists.lazarus.freepascal.org/pipermail/lazarus/2010-October/056098.html

I will check if this error of memory leak was repaired, if the class is normal in Lazarus now, I come back to use it.

Thanks guys. ;)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #12 on: January 31, 2011, 10:21:40 pm »
I don't think that "bug" was really problematic.
But might be fixed in the meantime:
http://bugs.freepascal.org/view.php?id=16884

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #13 on: January 31, 2011, 11:03:04 pm »
Btw. you could also use the Heartbeat feature to avoid "freezing" of your GUI.

http://synapse.ararat.cz/doku.php/public:howto:heartbeat

Silvio Clécio

  • Guest
Re: HTTPMethod in Synapse is slow and freezes program operation momentarily
« Reply #14 on: January 31, 2011, 11:05:03 pm »
Wow, this bug was solved:

http://bugs.freepascal.org/view.php?id=17560

Thanks. 8)

 

TinyPortal © 2005-2018