Recent

Author Topic: Use FreePascal for develop RESTFul services!!  (Read 316 times)

guest64351

  • Guest
Use FreePascal for develop RESTFul services!!
« on: August 20, 2019, 12:36:28 am »
Posts: 20
Personal Message (Offline)

Use FreePascal for develop RESTFul services

« on: March 26, 2019, 12:32:09 pm »
Quote
Hello:

I have much experience developing compiled CGI's with FreePascal, and now I want to develop an RESTFul service for mobiles apps.

Develop it is not problem, I want to know if is an good idea FreePascal instead PHP. I know that compiled CGI es much more fast than interpreted languages, but I know (by example) that PHP uses cache techniques and have integration with Apache. I think that CGI compiled load in memory one time and executes from there all times/app petitions, but I'm not sure.

What's your opinion?.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8103
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Use FreePascal for develop RESTFul services!!
« Reply #1 on: August 20, 2019, 07:22:18 am »
but I know (by example) that PHP uses cache techniques
opcode cache, if you enable it, which is still not a native code, simply skip the parsing and bytecode generation.
and have integration with Apache.
Not much different from CGI unless using the FastCGI module, which FPC is also capable of.
I think that CGI compiled load in memory one time and executes from there all times/app petitions, but I'm not sure.
This is OS level memory caching, the execution is still starting a new process for each request and kill it when done.
What's your opinion?.
Either use FastCGI or fphttpapp with reverse proxy if you're serious. Despite CGI having memory leak free feature, its one process per request handling isn't efficient. All of the initialization will be redone, just like in PHP. With either FastCGI or fphttpapp, the initialization can be run only once and the single (or several if you want) process(es) never die(s) until you tell it to, they keep listening for incoming request and stay alive after sending outgoing response.

lucamar

  • Hero Member
  • *****
  • Posts: 1986
Re: Use FreePascal for develop RESTFul services!!
« Reply #2 on: August 20, 2019, 04:13:08 pm »
Note also that you can develop Apache modules in Free Pascal. See: FPC and Apache Modules in the wiki.

Of course, and unlike CGI and FastCGI, it has the drawbacks that the application will only be usable under Apache or module-compatible servers, and that Apache modules are very version-dependent---though that can usually be solved with a recompilation.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2264
    • havefunsoft.com
Re: Use FreePascal for develop RESTFul services!!
« Reply #3 on: August 20, 2019, 04:21:58 pm »
Despite CGI having memory leak free feature, its one process per request handling isn't efficient. All of the initialization will be redone
I was wondering about that.
if we're talking about the end of 1990s, the performance difference between launching a process vs reusing the process would be more obvious.

I do remember, that Apache server even "preforked" itself for handing incoming connections. Just because fork+exec on Linux was pretty expensive operation (i.e. compered to CreateProcess() on Windows. The difference came, from the need of copying the memory of the forking process and then discarding it all together).

Since then OSes evolved (at least Linux adapted copy-on-write approach for fork+exec). Hardware evolved.
Software evolved. (Chromium library is multi-processed based, rather than multithreaded).
As of today, I'd consider that multi-processing is considered a bless, rather than a curse.

So CGI might be as efficient as FastCGI, due to reduced cost of starting a process, and obviously safer (in any regard).
OS control methods (such as Job Objects on Windows or cgroups on linux) can limit the resources availability for a (CGI) process spawned.
« Last Edit: August 20, 2019, 04:23:29 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Leledumbo

  • Hero Member
  • *****
  • Posts: 8103
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Use FreePascal for develop RESTFul services!!
« Reply #4 on: August 20, 2019, 05:31:22 pm »
I was wondering about that.
if we're talking about the end of 1990s, the performance difference between launching a process vs reusing the process would be more obvious.

I do remember, that Apache server even "preforked" itself for handing incoming connections. Just because fork+exec on Linux was pretty expensive operation (i.e. compered to CreateProcess() on Windows. The difference came, from the need of copying the memory of the forking process and then discarding it all together).

Since then OSes evolved (at least Linux adapted copy-on-write approach for fork+exec). Hardware evolved.
Software evolved. (Chromium library is multi-processed based, rather than multithreaded).
As of today, I'd consider that multi-processing is considered a bless, rather than a curse.

So CGI might be as efficient as FastCGI, due to reduced cost of starting a process, and obviously safer (in any regard).
OS control methods (such as Job Objects on Windows or cgroups on linux) can limit the resources availability for a (CGI) process spawned.
My latter concern is more important: reinitialization of resources, including but not limited to: config reading, database connection establishment, anything else besides request handling.
Also, while this is very project dependent, if one really consider speed as an important factor, long running vs one process per request handling will still show significantly different request per second.