title: Why FastCGI is so slow?
body: <p>Recently I've compared two versions of my C++ application that processes huge files (tens of GBs): a regular executable and fastcgi binary spawned under the lighttpd server. It turned out that fastcgi version was nearly 5 times slower. The program basically reads lots of lines from the files on the disc through FILE descriptors, fcgi version does exaclty the same. So where did the slowdown come from?</p>
  
  <p>Thanks for the comments! My program does the following:</p>
  
  <p>Initialization:
  - reads several files opened by fopen() line-by-line using fgets (a file contains several millions of lines)
  - builds some data structure in the RAM during files processing
  - outputs small log messages to a file on the disk after each file is processed</p>
  
  <p>Dialog:
  - the rest of time answers search queries via stdin/stdout</p>
  
  <p>And the FCGI version:
  FCGX_Init()</p>
  
  <p>Intialization (just as it was in the original version)</p>
  
  <p>while (FCGX_Accept()) {
      Dialog (through fcgi socket instead of stdin/stdout)
  }</p>
  
  <p>And I am talking only about initialization part performance. 
  I hope there is enough information now.</p>