Repository navigation
Description
With the current fork rate of about 50 forks/second, we might think to switch to FastCGI and reduce the overall system cpu time. Although starting the interpreter binary is quite fast, the high fork rate nevertheless adds some overhead. By using FastCGI, the interpreter binary would be serving multiple requests instead with lower overhead.
To avoid memory leaks, all locations with static buffers would have to be cleared, before handling the next request. There's one new method initialize() in scripting_core.cc for this purpose. I'm sure there are other locations, which need to be cleared in a similar way - or - even completely changed like:
static std::map< uint32, string > roles;in method relation_member_roles (collect_members.cc).static bool is_used_;for some statements like in area_query.hCoord_Query_Statement::is_used_in coord_query.ccId_Query_Statement::area_query_exists_in id_query.ccglobal_read_counter()in types.cc- ... and similar
Settings used for the prototype:
Install libs:
sudo apt-get install libfcgi-dev
sudo apt-get install libapache2-mod-fcgidApache settings:
default.conf
<Directory "/srv/overpass/fcgi-bin/">
SetHandler fcgid-script
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
#SetOutputFilter gzip
#Header set Content-Encoding gzip
</Directory>fcgid.conf: (needs to be adjusted in any case)
<IfModule mod_fcgid.c>
FcgidConnectTimeout 60
FcgidMaxRequestsPerProcess 500
FcgidMaxProcessesPerClass 20
FcgidMinProcessesPerClass 10
FcgidProcessLifeTime 300
FcgidMaxProcesses 20
FcgidIOTimeout 1800
<IfModule mod_mime.c>
AddHandler fcgid-script .fcgi
</IfModule>
</IfModule>
Activity
mmd-osm commentedon Jun 9, 2016
In addition, FastCGI can be combined with a buffer for data_files / random_files in Nonsynced_Transaction
As FastCGI handles multiple queries anyway, the buffer can be reused for several queries in the best case.
Same applies to User_Data_Cache: it only changes after a db update, but is re-read for every transaction in need of user data.
This is largely improving the runtime for very short running queries, like:
8 concurrent threads, no wait time. No DB updates, on dev instance: 21 calls/s.
(includes #208, #280)
mmd-osm commentedon Dec 21, 2016
Some comments on configuration:
interpreter binary can also be managed via supervisord and the following configuration example:
This way,
interpretercan run under a dedicated user rather than www-data. It an instances crashes, it will be automatically restarted.For nginx (and also Apache), we can directly connect to the respective unix socket:
mmd-osm commentedon Nov 15, 2021
Change implemented in https://github.com/mmd-osm/Overpass-API, closing here.