Make includes free to the user (application support component)
Summary:
We spend a significant amount of time running includes, even with APC. However, we have rigidly structured includes and can safely run them all in workers before requests occur.
Right now, requests go like this:
- Apache spawns a worker.
- Client sends an HTTP request.
- Apache interprets it.
- Apache sees it's ".php", so it hands it off to the PHP SAPI.
- The PHP SAPI starts the PHP interpreter in the worker.
- The request is handled, etc.
Instead, we want to do this:
- Worker spawns and loads the world.
- Client sends an HTTP request.
- Webeserver interprets it.
- Sees it's a ".php", hands it off to the SAPI.
- SAPI executes it on a loaded world.
No SAPIs I know of support this, but I added support to PHP-FPM fairly easily (in the sense that it took me 6 hours and I have a hacky, barely-working mess). Over HTTP (vs HTTPS) the performance improvement is pretty dramatic.
HPHP doesn't significantly defray this cost so we're probably quite a bit faster (to the user) under nginx+PHP-FPM than HPHP after this works for real.
I have the php-fpm half of this patch in a messy state, I'm going to try to port it to be vs php 5.4.
Test Plan: Ran a patched php-fpm, browsed around, site works, appears dramatically faster.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D2030
2012-03-28 01:06:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTE: This is an ADVANCED feature that improves performance but adds a lot
|
|
|
|
* of complexity! This is only suitable for production servers because workers
|
|
|
|
* won't pick up changes between when they spawn and when they handle a request.
|
|
|
|
*
|
|
|
|
* Phabricator spends a significant portion of its runtime loading classes
|
|
|
|
* and functions, even with APC enabled. Since we have very rigidly-defined
|
|
|
|
* rules about what can go in a module (specifically: no side effects), it
|
|
|
|
* is safe to load all the libraries *before* we receive a request.
|
|
|
|
*
|
|
|
|
* Normally, SAPIs don't provide a way to do this, but with a patched PHP-FPM
|
|
|
|
* SAPI you can provide a warmup file that it will execute before a request
|
|
|
|
* is received.
|
|
|
|
*
|
|
|
|
* We're limited in what we can do here, since request information won't
|
|
|
|
* exist yet, but we can load class and function definitions, which is what
|
|
|
|
* we're really interested in.
|
|
|
|
*
|
|
|
|
* Once this file exists, the FCGI process will drop into its normal accept loop
|
|
|
|
* and eventually process a request.
|
|
|
|
*/
|
|
|
|
function __warmup__() {
|
|
|
|
$root = dirname(dirname(dirname(dirname(__FILE__))));
|
|
|
|
require_once $root.'/libphutil/src/__phutil_library_init__.php';
|
|
|
|
require_once $root.'/arcanist/src/__phutil_library_init__.php';
|
|
|
|
require_once $root.'/phabricator/src/__phutil_library_init__.php';
|
|
|
|
|
|
|
|
// Load every symbol. We could possibly refine this -- we don't need to load
|
|
|
|
// every Controller, for instance.
|
|
|
|
$loader = new PhutilSymbolLoader();
|
|
|
|
$loader->selectAndLoadSymbols();
|
|
|
|
|
2012-03-28 19:13:53 +02:00
|
|
|
// Force load of the Celerity map.
|
|
|
|
CelerityResourceMap::getInstance();
|
|
|
|
|
Make includes free to the user (application support component)
Summary:
We spend a significant amount of time running includes, even with APC. However, we have rigidly structured includes and can safely run them all in workers before requests occur.
Right now, requests go like this:
- Apache spawns a worker.
- Client sends an HTTP request.
- Apache interprets it.
- Apache sees it's ".php", so it hands it off to the PHP SAPI.
- The PHP SAPI starts the PHP interpreter in the worker.
- The request is handled, etc.
Instead, we want to do this:
- Worker spawns and loads the world.
- Client sends an HTTP request.
- Webeserver interprets it.
- Sees it's a ".php", hands it off to the SAPI.
- SAPI executes it on a loaded world.
No SAPIs I know of support this, but I added support to PHP-FPM fairly easily (in the sense that it took me 6 hours and I have a hacky, barely-working mess). Over HTTP (vs HTTPS) the performance improvement is pretty dramatic.
HPHP doesn't significantly defray this cost so we're probably quite a bit faster (to the user) under nginx+PHP-FPM than HPHP after this works for real.
I have the php-fpm half of this patch in a messy state, I'm going to try to port it to be vs php 5.4.
Test Plan: Ran a patched php-fpm, browsed around, site works, appears dramatically faster.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D2030
2012-03-28 01:06:13 +02:00
|
|
|
define('__WARMUP__', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
__warmup__();
|