As you may be aware, the front end of the PubReviews.com website is built using ReactJS. I wrote about it here.
For SEO purposes we utilise server side rendering of Javascript components (woo ! Isomorphic Javascript) such that on page load the user (or search engine) gets an instantaneous, near complete rendering of the pages interface.
To render Javascript on the server side we utilise V8JS. It works really well, but unfortunately we have encountered a few memory related issues in our error logs.
The problem almost certainly pertains to the fact that search engine robots often hit a lot of pages in short succession. It is apparent as to why server side rendering of Javascript might be memory intensive and as such combined with large number of requests it seems logical that one might get errors like these:
Committing semi space failed. Allocation failed - process out of memory
PHP Fatal error: Evacuation Allocation failed - process out of memory
V8Js::__construct(): Failed to create V8 context
Resolution
It may seem like a simple resolution would be to simply increase the memory resources available on the server. I did in fact do this, and it did not reduce the occurrence of the issues. I thus felt it worthwhile to investigate other resolutions, namely making sure that I was utilising the most up to date version of v8 and v8js respectively.
To my surprise it turns out that the version of v8 available within Ubuntu's package manager (at the time of writing) is 3.14.15. Given that the current version is 5.1.0 it is apparent that this version is seriously outdated.
To update v8 we are therefore going to have to manually build the latest version. This is a little more complex than using a one line package manager, but is unfortunately a necessary evil.
One obvious benefit is that by compiling yourself you put yourself in control of the specific library versions that you are using. You can compile specific versions consistently across platforms. There is no need to introduce errors or inconsistencies as a result of having one version of v8 on your Mac (through MacPorts) and another on your server (through aptitude).
stesie (of phpv8 fame) outlines this here, and an explanation of how you go about compiling the latest version of v8 can be found here.
Issues
I encountered a few issues in the process, and as such I thought I would outline them for anyone having troubles.
-
Using depot_tools to pull in the v8 source is in and of itself memory intensive. I had issues which were resolved simply by increasing the memory available.
-
The build steps are likewise memory intensive.
-
When building v8 I got a number of errors pertaining to ICU. Now I was (and still am) blissfully ignorant (my bad) of how 'building' works behind the scenes and what exactly 'ICU' is. That said installing the ICU library using the following command resolved my issues:
sudo apt-get install libicu-dev
.
Compiling v8js
Once you have compiled v8, you need to install the appropriate version of v8js.
Whilst you can utilise PECL to do this on Ubuntu, you may as well compile it yourself such that (once again) you can have fine grained control over the version that you are using.
The only issue I encountered regarding compiling v8js is that there are now different versions of the library depending on if you are running PHP 5.x or PHP 7. You need to make sure that you clone the master branch if using PHP 5.x.
Results
As of now this has resolved my issues entirely ! We have had no memory issues within our error logs.
That said, it has only been half an hour since I updated to version 5.1.0 (v8) and 0.6.0 (v8js) respectively :)