I have a PHP web script that accepts a user-entered regular expression and uses it to search a large text file (9.4 million lines, around 160MB). In the first iteration of my script, I had the file sitting on a regular file system, and when I needed to search it, I would access it using fopen / fgets and search it line by line. Depending on the complexity of the regular expression, the script got through the entire file in 30-45 seconds.
To try and speed it up, I mounted a 1GB tmpfs partition and moved the large text file onto it. I then changed the path in the PHP script, and was hoping to see immediate improvement. However, the speed at which the script parsed through the file hasn't changed, and on multiple runs, sometimes appeared slower than when reading the file from a regular file system.
Furthermore, I tried loading the entire file into RAM in PHP, but pulling it into an array first, which did improve the search time by 40% or so. This is not an acceptable way to go for me, unfortunately, since the initial loading-file-into-an-array time is quite long.
This is all happening on a virtual server with 12GB of RAM, running Debian 7, with nginx / php5-fpm.
What is happening with my tmpfs? Is there something I am missing? I'll supply whatever additional information necessary.