Rails page caching for improved performance

JonthumbPosted by Jonathan Weyermann on January 30, 2018 at 12:00 AM
Rails cache broken

In order to reduce the load on your server and allow more concurrent users to hit your website, you may use caching. There are many types of caching in Ruby on Rails, some of which are discussed in the guides. Some require the use of a dedicated caching service such as AWS's Elasticache (memcache or redis). The minimum cost of one of those instances is the same as a t2 micro. If you are only running a simple Rails app, this service may not be worth it, especially since there is a simple method of caching that doesn't cost anything extra and provides an immense speed boost in many situations. This is described in the Rails guides as page caching, and while it was removed the Rails core since Rails 4, there is still a handy gem that provide the same functionality called actionpack-page_caching. This caching creates a html only snapshot of your rails page, and allows it to be rendered by only Nginx or Apache, which should be much faster. I personally installed in on my own rails blog (this site) using the instructions and here are the results (I did this test with Apache Bench -> I ran  


ab -n 1000 -c 100 http://localhost:3000/

where 3000 is the local reverse forwarding port of my Nginx server

Before this change, here are the results


Server Software:        nginx/1.10.2
Server Hostname:        localhost
Server Port:            3000

Document Path:          /
Document Length:        17147 bytes

Concurrency Level:      100
Time taken for tests:   130.231 seconds
Complete requests:      1000
Failed requests:        98
(Connect: 0, Receive: 0, Length: 98, Exceptions: 0)
Non-2xx responses:      98
Total transferred:      16733866 bytes
HTML transferred:       15933070 bytes
Requests per second:    7.68 [#/sec] (mean)
Time per request:       13023.087 [ms] (mean)
Time per request:       130.231 [ms] (mean, across all concurrent requests)
Transfer rate:          125.48 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    2   4.2      0      16
Processing:    60 12789 22374.0   5491   85057
Waiting:       52 12764 22355.9   5484   85054
Total:         63 12790 22373.3   5491   85057

Percentage of the requests served within a certain time (ms)
50%   5491
66%   5742
75%   6160
80%   7752
90%  45290
95%  82171
98%  83974
99%  84495
100%  85057 (longest request)


The results after applying the caching are here 

Server Software:        nginx/1.10.2
Server Hostname:        localhost
Server Port:            3000

Document Path:          /
Document Length:        189 bytes

Concurrency Level:      100
Time taken for tests:   25.383 seconds
Complete requests:      1000
Failed requests:        46
(Connect: 0, Receive: 0, Length: 46, Exceptions: 0)
Non-2xx responses:      954
Total transferred:      1283196 bytes
HTML transferred:       969068 bytes
Requests per second:    39.40 [#/sec] (mean)
Time per request:       2538.254 [ms] (mean)
Time per request:       25.383 [ms] (mean, across all concurrent requests)
Transfer rate:          49.37 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0   56 169.4      0     986
Processing:    11 2036 5814.8     62   23053
Waiting:       11 2035 5813.1     61   23053
Total:         11 2093 5982.0     62   23611

Percentage of the requests served within a certain time (ms)
50%     62
66%     70
75%     78
80%     82
90%  18281
95%  18288
98%  22617
99%  23073
100%  23611 (longest request)


As you can see, the requests per second went from 7.68/second to  almost 39.4/second, most requests were much faster, and there were fewer failing requests.

In theory, the gem suggests that you have to call expire_page when updating a page, for instance when a comment is added or when a post is updated, but I've found that this seems to be unnecessary. The gem seems to know on it's own when to invalidate the page and reload it.

I would not expect this gem to provide much of a performance speedup if each user has a login area or a customized browsing experience. A new page would be generated each time it was different that a previously cached page. However, it's absolutely brilliant for a blog where each user sees that same content. I suspect that it's limited usefulness in many rails applications is the reason it was removed from the base install in Rails 4. Nevertheless, In the correct use case the performance gain is massive.

User

minimaxSeptember 5 2020 at 3:16 AM

Здесь вы можете Купить игры на XBOX ONE получить бесплатно подарки + https://plati.market/itm/need-for-speed-payback-us-xbox-live/2920504
Reply
User

mmmaximSeptember 22 2020 at 1:48 AM

Купить цифровые версии игр XBOX ONE и изучать английский поставив ангилийский и русские субтитры + https://plati.market/itm/far-cry-5-us-xbox-key/2907750 Купить цифровые версии игры +для xbox +one и поиграть + https://vk.com/public195417980
Reply
User

UltimateJune 19 2022 at 2:45 PM

Hi, would you like more business leads at a lower cost? Currently http://GetMoreBusinessLeadsNow.com is offering our popular unlimited lead generation software package - at a reduced price for a limited time. Download and install now to be building databases of leads in minutes: http://GetMoreBusinessLeadsNow.com The Ultimate Lead Generation Pack works by automatically visting yellow page directories and building a database according to your search terms. Other software in the pack then finds emails, phone numbers, and other details for that database. The results can be used for email, cold-calling, direct mail, or to sell immediately - priced per lead. Runs on Windows, Mac, and Linux with multiple job and VPN/proxy support. Similar software retails for over $100 with less features. This pack is only available on sale as a short promotional offer, please download now if at all interested. Click Here: http://GetMoreBusinessLeadsNow.com Have a Great Day, The Ultimate Lead Generation Pack Team unsubscribe/remove Here: http://getmorebusinessleadsnow.com/r.php?url=jonathanweyermann.com&id=ulg35
Reply
User

GetMyBusinessFundingNowJune 24 2022 at 1:14 AM

Hi, do you know that http://GetMyBusinessFundingNow.com can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://GetMyBusinessFundingNow.com Requirements include your company being established for at least a year and with current gross revenue of at least 120K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://GetMyBusinessFundingNow.com Have a good day, The Get My Business Funding Now Team unsubscribe/remove - http://GetMyBusinessFundingNow.com/r.php?url=jonathanweyermann.com&id=113
Reply
User

UltimateJune 26 2022 at 2:43 PM

Hi, would you like more business leads at a lower cost? Currently http://GetMoreBusinessLeadsNow.com is offering our popular unlimited lead generation software package - at a reduced price for a limited time. Download and install now to be building databases of leads in minutes: http://GetMoreBusinessLeadsNow.com The Ultimate Lead Generation Pack works by automatically visting yellow page directories and building a database according to your search terms. Other software in the pack then finds emails, phone numbers, and other details for that database. The results can be used for email, cold-calling, direct mail, or to sell immediately - priced per lead. Runs on Windows, Mac, and Linux with multiple job and VPN/proxy support. Similar software retails for over $100 with less features. This pack is only available on sale as a short promotional offer, please download now if at all interested. Click Here: http://GetMoreBusinessLeadsNow.com Have a Great Day, The Ultimate Lead Generation Pack Team unsubscribe/remove Here: http://getmorebusinessleadsnow.com/r.php?url=jonathanweyermann.com&id=ulg35
Reply
User

BusinessCapitalAdvisorJune 30 2022 at 2:37 PM

Hi, do you know that http://BusinessCapitalAdvisor.info can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://BusinessCapitalAdvisor.info Requirements include your company being established for at least a year and with current gross revenue of at least 120K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://BusinessCapitalAdvisor.info Have a good day, The Business Capital Advisor Team unsubscribe/remove - http://BusinessCapitalAdvisor.info/r.php?url=jonathanweyermann.com&id=114
Reply
User

UltimateJuly 4 2022 at 4:43 AM

Hi, would you like more business leads at a lower cost? Currently http://GetMoreBusinessLeadsNow.com is offering our popular unlimited lead generation software package - at a reduced price for a limited time. Download and install now to be building databases of leads in minutes: http://GetMoreBusinessLeadsNow.com The Ultimate Lead Generation Pack works by automatically visting yellow page directories and building a database according to your search terms. Other software in the pack then finds emails, phone numbers, and other details for that database. The results can be used for email, cold-calling, direct mail, or to sell immediately - priced per lead. Runs on Windows, Mac, and Linux with multiple job and VPN/proxy support. Similar software retails for over $100 with less features. This pack is only available on sale as a short promotional offer, please download now if at all interested. Click Here: http://GetMoreBusinessLeadsNow.com Have a Great Day, The Ultimate Lead Generation Pack Team unsubscribe/remove Here: http://getmorebusinessleadsnow.com/r.php?url=jonathanweyermann.com&id=ulg37
Reply
User

GetMyBusinessFundedNowJuly 7 2022 at 8:36 AM

Quicker and Easier than the SBA, http://GetMyBusinessFundedNow.info can get your business a loan for $2K-350,000 With low-credit and without collateral. Use our 1 minute form to Find Out exactly how much you can get, No-Cost: http://GetMyBusinessFundedNow.info If you've been in business for at least a year you are already pre-qualified. Our Fast service means funding can be finished within 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get. This is a free service from a qualified lender and the approval will be based on the annual revenue of your business. Funds are also Non-Restrictive, allowing you to use the whole amount in any way including bills, taxes, hiring, marketing, expansion, or Absolutely Any Other expense. There are limited SBA and private funds available so please apply now if interested, Click Here: http://GetMyBusinessFundedNow.info Have a great day, The Get My Business Funded Now Team unsubscribe here - http://GetMyBusinessFundedNow.info/r.php?url=jonathanweyermann.com&id=115
Reply
User

GetMyBusinessFundingNowJuly 13 2022 at 10:10 AM

Hi, do you know that http://GetMyBusinessFundingNow.com can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://GetMyBusinessFundingNow.com Requirements include your company being established for at least a year and with current gross revenue of at least 120K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://GetMyBusinessFundingNow.com Have a good day, The Get My Business Funding Now Team unsubscribe/remove - http://GetMyBusinessFundingNow.com/r.php?url=jonathanweyermann.com&id=116
Reply
User

FastFundingAdvisorsJuly 15 2022 at 9:14 PM

Faster and Easier than the SBA, http://FastFundingAdvisors.info can get your business a loan for $2K-350,000 With low-credit and no collateral. Use our 1 minute form to Find Out exactly how much you can get, No-Cost: http://FastFundingAdvisors.info If you've been in business for at least 1 year you are already pre-qualified. Our Fast service means funding can be completed within 48 hours. Terms are specific for each business so I suggest applying to find out exactly how much you can get. This is a free service from a qualified lender and the approval will be based on the annual revenue of your business. Funds are also Non-Restrictive, allowing you to use the full amount in any way including bills, taxes, hiring, marketing, expansion, or Absolutely Any Other expense. There are limited SBA and private funds available so please apply now if interested, Click Here: http://FastFundingAdvisors.info Have a great day, The Fast Funding Advisors Team unsubscribe here - http://FastFundingAdvisors.info/r.php?url=jonathanweyermann.com&id=117
Reply
User

GetMyBusinessFundedNowJuly 20 2022 at 4:08 AM

Hi, do you know that http://GetMyBusinessFundedNow.pro can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://GetMyBusinessFundedNow.pro Requirements include your company being established for at least a year and with current gross revenue of at least 120K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://GetMyBusinessFundedNow.pro Have a good day, The Get My Business Funded Now Team unsubscribe/remove - http://GetMyBusinessFundedNow.pro/r.php?url=jonathanweyermann.com&id=118
Reply
User

FastCapitalAdvisorsJuly 22 2022 at 1:47 PM

Quicker and Simpler than the SBA, http://FastCapitalAdvisors.com can get your business a loan for $2K-350,000 With low-credit and without collateral. Use our short form to See exactly how much you can get, No-Cost: http://FastCapitalAdvisors.com If you've been in business for at least a year you are already pre-qualified. Our Fast service means funding can be completed within 48 hours. Terms are specific for each business so I suggest applying to find out exactly how much you can get. This is a free service from a qualified lender and the approval will be based on the annual revenue of your business. Funds have no Restrictions, allowing you to use the whole amount in any way including bills, taxes, hiring, marketing, expansion, or Absolutely Any Other expense. There are limited SBA and private funds available so please apply now if interested, Click Here: http://FastCapitalAdvisors.com Have a great day, The Fast Capital Advisors Team unsubscribe here - http://FastCapitalAdvisors.com/r.php?url=jonathanweyermann.com&id=119
Reply
User

FastCapitalAdvisorsJuly 26 2022 at 9:18 PM

Faster and Easier than the SBA, http://FastCapitalAdvisors.pro can get your business a loan for $2K-350,000 With low-credit and no collateral. Use our short form to Find Out exactly how much you can get, No-Cost: http://FastCapitalAdvisors.pro If you've been in business for at least one year you are already pre-qualified. Our Quick service means funding can be completed within 48hrs. Terms are specific for each business so I suggest applying to find out exactly how much you can get. This is a free service from a qualified lender and the approval will be based on the annual revenue of your business. Funds have no Restrictions, allowing you to use the whole amount in any way including bills, taxes, hiring, marketing, expansion, or Absolutely Any Other expense. There are limited SBA and private funds available so please apply now if interested, Click Here: http://FastCapitalAdvisors.pro Have a great day, The Fast Capital Advisors Team remove here - http://FastCapitalAdvisors.pro/r.php?url=jonathanweyermann.com&id=120
Reply
User

BusinessCapitalAdvisorJuly 29 2022 at 4:50 AM

Hi, do you know that http://BusinessCapitalAdvisor.pro can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://BusinessCapitalAdvisor.pro Requirements include your company being established for at least a year and with current gross revenue of at least 120K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://BusinessCapitalAdvisor.pro Have a good day, The Business Capital Advisor Team unsubscribe/remove - http://BusinessCapitalAdvisor.pro/r.php?url=jonathanweyermann.com&id=121
Reply
User

GetBusinessFundedNowAugust 1 2022 at 4:13 AM

Faster and Simpler than the SBA, http://GetBusinessFundedNow.pro can get your business a loan for $2K-350,000 With low-credit and no collateral. Use our short form to See exactly how much you can get, No-Cost: http://GetBusinessFundedNow.pro If you've been established for at least 12 months you are already pre-qualified. Our Fast service means funding can be finished within 48hrs. Terms are specific for each business so I suggest applying to find out exactly how much you can get. This is a free service from a qualified lender and the approval will be based on the annual revenue of your business. Funds are also Non-Restrictive, allowing you to use the full amount in any way including bills, taxes, hiring, marketing, expansion, or Absolutely Any Other expense. There are limited SBA and private funds available so please apply now if interested, Click Here: http://GetBusinessFundedNow.pro Have a great day, The Get Business Funded Now Team remove here - http://GetBusinessFundedNow.pro/r.php?url=jonathanweyermann.com&id=122
Reply
User

FastCapitalAdvisorsAugust 3 2022 at 2:55 PM

Hi, do you know that http://FastCapitalAdvisors.com can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://FastCapitalAdvisors.com Requirements include your company being established for at least a year and with current gross revenue of at least 180K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://FastCapitalAdvisors.com Have a good day, The Fast Capital Advisors Team unsubscribe/remove - http://FastCapitalAdvisors.com/r.php?url=jonathanweyermann.com&id=123
Reply
User

MyBusinessFundedNowAugust 6 2022 at 2:38 AM

Quicker and Easier than the SBA, http://MyBusinessFundedNow.com can get your business a loan for $2K-350,000 With low-credit and without collateral. Use our quick form to See exactly how much you can get, No-Cost: http://MyBusinessFundedNow.com If you've been in business for at least 1 year you are already pre-qualified. Our Fast service means funding can be completed within 48hrs. Terms are specific for each business so I suggest applying to find out exactly how much you can get. This is a free service from a qualified lender and the approval will be based on the annual revenue of your business. Funds have no Restrictions, allowing you to use the whole amount in any way including bills, taxes, hiring, marketing, expansion, or Absolutely Any Other expense. There are limited SBA and private funds available so please apply now if interested, Click Here: http://MyBusinessFundedNow.com Have a great day, The My Business Funded Now Team unsubscribe here - http://MyBusinessFundedNow.com/r.php?url=jonathanweyermann.com&id=124
Reply
User

GetMyBusinessFundingNowAugust 10 2022 at 7:09 AM

Hi, do you know that http://GetMyBusinessFundingNow.com can help your business get funding for $2,000 - $350K Without high credit or collateral. Find Out how much you can get by clicking here: http://GetMyBusinessFundingNow.com Requirements include your company being established for at least a year and with current gross revenue of at least 180K. Eligibility and funding can be completed in as fast as 48hrs. Terms are personalized for each business so I suggest applying to find out exactly how much you can get on various terms. This is a completely free service from a qualified funder and the approval will be based on the annual revenue of your business. These funds are completely Non-Restrictive, allowing you to spend the full amount in any way you require including business debt consolidation, hiring, marketing, or Absolutely Any Other expense. If you need fast and easy business funding take a look at these programs now as there is limited availability: http://GetMyBusinessFundingNow.com Have a good day, The Get My Business Funding Now Team unsubscribe/remove - http://GetMyBusinessFundingNow.com/r.php?url=jonathanweyermann.com&id=124
Reply

Add Comment