- PeterMoulding.com
- Author
- Trainer
- Speaker
- Business Coach
- How to write a How To book
- PHP Courses
- Speaking
- Web Architect
- Australia
- Books
- Authors
- Akkana Peck
- Alex Berenson
- Andrew Nugent
- Ben Sanders
- Brock Clarke
- Chris Simms
- David Mercer
- Dianna Mullet
- Don Winslow
- Dori Smith
- Harlan Coben
- Jack McDevitt
- James Wines
- Jerry Yudelson
- John Grisham
- Kevin Mullet
- L. E. Modesitt Jr.
- Laurell K. Hamilton
- Marshall Karp
- Martina Cole
- Michael Marshall Smith
- Michel Roux Jr
- Nadia Sawalha
- Philip Pullman
- Raymond Khoury
- Richard North Patterson
- Robert Masello
- Sally Roth
- Sarah Langan
- Stella Rimington
- Stephen Booth
- Stephen King
- Stephen Leather
- T.C. Boyle
- Tom Negrino
- Tony Hillerman
- Urban Waite
- Val McDermid
- Valerio Massimo Manfredi
- Beginning GIMP
- Beginning Visual C++
- Culturalism
- Fiction
- A Drink Before The War
- A Talent for War
- Bag of Bones
- Blood and Ice
- Burn
- Dark Lady
- Dead Line
- Eclipse
- Empress of Eternity
- Exley
- Flipping Out
- Just One Look
- Nightfall
- Pet Sematary
- Savage Moon
- Skinwalkers
- Starvation Lake
- The Fallen
- The Gardens of the Dead
- The Jump
- The Last Templar
- The Mermaids Singing
- The Midnight Mayor
- The Secret Soldier
- The Summons
- The Terror of Living
- The Testament
- The Tower
- Under the Dome
- Virus
- AJAX and PHP
- Aging with Grace
- Food books
- Green Architecture
- Life Is So Good
- SQL: The Complete Reference
- The Backyard Bird Lover's Ultimate How-to Guide
- The Garden Gurus
- Authors
- Sustainability
- -18 hours left to decide the future of Australia
- Campbells vegetable stock or Massel vegetable stock?
- Carbon Sequestration
- Carbon tax for Australia is a fraud
- Copenhagen will fail
- Cost of living in Australia
- Dick Smith jumps on the population bandwagon
- Dry Run: Preventing the Next Urban Water Crisis
- Energy Saving Lights
- Garlic
- How many people can live in Australia?
- Its obsolete, throw it out!
- Julia Gillard offers 9.9 billion dollars bribe to Rob Oakeshott
- Laundry detergent
- Petrol or Diesel?
- Reflective foil batts kill
- RoHS
- Sea level to rise 3mm due to climate change
- Solar power
- Spring again in Sydney
- Sustainable fuels
- The CRUD Tax is back
- The people who make building regulations do not own houses
- Water efficiency
- Which insulation is safer, foil or wool?
- Will Australia reduce greenhouse gas emissions?
- Technology
- Android or Blackberry or iPhone or a flip phone?
- Apple versus Google 2011
- Cameras
- Cars
- Colour
- Burgundy
- Colour Blindness
- Colour Names
- Dulux colours
- Pantone colours
- Safe Colours
- Seculine ProDisk Mini colour balance card
- What Causes Colour Blindness?
- Hardware
- Batteries for the Digital Age
- Cables
- Cases
- Computer reliability
- Computrace
- Disks
- Astone ISO Gear 481E
- Best SSD for your notebook computer
- Disk block size
- Hitachi disk HDS722020ALA330
- LaCie USB 2.0 250 GB mobile hard drive design by F.A. Porsche
- SMART disk
- Samsung 2 TB HD204UI quiet low power disk for mass storage
- Seagate and Samsung merge disk business
- Select the right disk for your RAID array
- USB disk speed
- Western Digital WD20EARX 2 GB SATA 3 disk
- How long should computer hardware last?
- Keyboards
- Mainframe
- Memory cards
- Monitors
- Netbooks, notebooks, tablets, and xPads
- Network Attached Storage
- OLED Displays
- PC's are a thing of the past
- Printers
- Quiet
- Samsung Galaxy S
- Speed
- Television
- Tools
- USB
- Worst computer movies
- Xserve is dead. What next?
- Your backup will not work
- Z68 motherboards
- iPad or Acer Aspire One?
- IQ
- LG Intello Washing Machine
- Lack of a challenge
- Networks
- 802.11n wireless networking
- D-Link DIR-655 wireless router
- D-Link DWA-160 Xtreme N dual band USB adapter
- D-Link DWA-556 Xtreme N PCI Express desktop adapter
- MIMO
- NBN spends another $12 billion of our tax money on nothing
- National Broadband Network
- Netgear wireless modem router DGND3300 with 300 Mbps 802.11n
- Refrigerator kills wireless broadband
- Small Wireless Network
- TP-LINK TL-SG10005D 5 port gigabit switch
- TP-Link TL-WR1043N wireless N gigabit router
- Telstra Pre-paid Mobile Wi-Fi
- Where are the router plus proxy server combinations?
- Open Source documentation
- Software
- 7-zip
- Accounting
- Asterisk
- Audacity
- Backup software
- Bloat only in Windows
- CAD
- CDex
- Disk imaging software for copying and backup
- Exact Audio Copy
- Filezilla
- Firefox
- Java
- LibreOffice or OpenOffice?
- Linux
- 1 in 5 servers will ship with Linux
- Android phones outsell iPhone
- Another Move to Linux
- CentOS 5.5 installation on SSD and RAID 5
- Debian
- Debian 5.0.5 AMD64 installation
- Debian 5.06 installation
- Fedora
- Fedora or Ubuntu?
- Gnome or KDE?
- K9copy
- Linux 2.6.38
- Linux Gnome login settings lost
- Linux Mint
- Linux RAID, a rant
- Linux Speed
- Linux Time
- Linux reliability as demonstrated by Ubuntu 10.10
- Linux reliability as demonstrated by Ubuntu 11.4
- Linux still a struggle in 2011
- Linux workstation disk RAID 1
- Linux, NT, Windows, and SETI
- Linux, three years of progress
- London Stock Exchange switches to Linux
- Mandrake Linux 9.2
- The partition is misaligned by 48128 bytes - warning from Linux RAID
- Ubuntu
- How to fix the scroll bars in Ubuntu 11.4 Gnome
- Kubuntu 10.10 alternate installation on desktop with RAID 1
- POWbuntu
- Ubuntu 10.10 after 6 months use
- Ubuntu 10.10 alternate installation
- Ubuntu 10.10 desktop RAID 1
- Ubuntu 10.10 desktop RAID 5
- Ubuntu 10.10 desktop install on a netbook
- Ubuntu 10.10 desktop installation
- Ubuntu 10.10 netbook install on a netbook
- Ubuntu 10.10 server AMD64
- Ubuntu 10.10 upgrade to version 11.4 beta 2
- Ubuntu 10.4
- Ubuntu 11.10
- Ubuntu 11.10 first upgrade
- Ubuntu 11.4 after one month use
- Ubuntu 12.04 beta1 desktop amd64
- Ubuntu One
- Ubuntu by Microsoft?
- Ubuntu desktop upgrade 10.4 to 10.10 failed because I did not check the media
- Ubuntu strikes again
- Upgrade Ubuntu to Linux Mint 12 LDXE for extra speed
- Yes, use Linux but not that distribution!
- Nero
- OpenOffice
- OpenOffice is now Apache Office
- Project management
- Scribus
- Software for Windows and Linux
- Text editors
- Time
- Todo applications
- Tomboy notes
- Top text editors
- Version control
- VideoLAN VLC media player
- Visio
- Webmin
- Webmin installation on CentOS for Web development
- Webmin installation on Ubuntu
- What is the most popular open source software today?
- Windows
- Another Windows person goes Linux
- BAD_POOL_CALLER
- Cygwin
- Microsoft Malicious Software Removal Tool cannot find a common virus
- One of the developers of Windows XP is criminally insane
- There are unused icons on your desktop
- W32time
- Which Windows version?
- Windows 7 Home Premium
- Windows XP Stop 0x0000007B during installation
- Windows XP is a disaster
- Windows processes
- XML
- Zip, bzip, gzip, or 7zip?
- configFree
- Technology Succession Planning
- VoIP
- Web Sites
- Drupal
- Do Drupal themes have to use the GPL?
- Drupal 7
- A better search facility for Drupal
- Drupal - performance or flexibility
- Drupal 7 Fields are hard to fix
- Drupal 7 new features
- Drupal 7 ships on January 5
- Drupal 7.14
- Drupal 7.4 hits PeterMoulding.com
- Drupal function sequence
- The evolution of a module
- Undefined index: headers in DefaultMailSystem->mail() (line 54 of /modules/system/system.mail.inc).
- Undefined index: to in DefaultMailSystem->mail() (line 83 of /modules/system/system.mail.inc).
- implode(): Invalid arguments passed in DefaultMailSystem->format() (line 23 of /modules/system/system.mail.inc).
- Drupal 8
- Drupal Code Load Cut
- Drupal How To
- Drupal Modules
- Backup and Migrate
- Browscap
- CKEditor with Drupal WYSIWYG
- Captcha
- Cel
- Colorbox
- Content Construction Kit
- Content type
- Devel module for Drupal
- Drupal Rules as an automation language
- Drupal Spam add-on module
- Form alter to node
- IMCE
- IMCE Wysiwyg bridge
- ImageAPI
- Jdog
- Lightbox2
- Module variable
- Node Gallery Access
- Node_Gallery
- Path
- Path redirect
- Pathauto
- Pet
- Search
- Service links
- Session Variable
- Statistics
- Taxonomy
- Token
- Token ex
- Transliteration
- Trigger
- Watch
- Other modules
- Drupal Training
- Drupal access controls need a major rewrite
- Drupal coding tricks
- Drupal performance
- Drupal themes for the future
- Drupal.org colours
- Import existing data into Drupal
- Multiple Web sites made easy using Drupal multisite and the right start
- drupal_lookup_path()
- Adobe PDF
- Apache
- Apache Mahout
- Audi.com
- Bleet
- CSS Strikes Again
- CSS or xCSS
- Can you believe Facebook or email?
- Content Management Systems
- Databases
- Facebook scam
- Font
- Fonts
- HTML
- Install Apache, MySQL, and PHP 5 in Ubuntu 11.4 using the Ubuntu Software Centre
- Language Codes
- Marketing
- Memcache
- Nginx
- Open source development hits another roadblock
- Oscars
- PHP
- SPDY
- Search software
- Techoni.com.au
- Theme themes
- Things to hate on Web sites
- U.S. Patent No. 6,985,875
- Virtual Private Server
- Visible Improvement
- Web 4.0
- Web browser usage
- Web browsers
- Web site development
- Bluefish
- Crying over spilt code
- Eclipse and PHP
- Getting a Git client, a story of ancient technology and pain
- HTTrack
- MVC
- Netbeans
- PHP or ..., CakePHP/Symfony/ZF versus ...
- Programming
- Superfish
- Web browser emulators for testing your Web site
- Web development frameworks
- Web site books
- Web site development on your own computer
- Webmin or phpMyAdmin or cPanel for creating databases?
- aiki framework
- jQuery
- Views development - Learn Fields first
- Views development - Learn Actions and Rules
- jQuery .each()
- jQuery .has()
- jQuery .is()
- jQuery and Firefox Firebug
- jQuery children
- jQuery for people not using Drupal - Installation and getting started
- jQuery hover
- jQuery hover de-duplication example
- jQuery or CSS?
- jQuery performance
- jQuery tests
- Web site hosting
- Westpac Web site still broken after two years and ten months
- Wordpress wins another CMS survey
- Drupal
Memcache
Submitted by Peter on Tue, 2009-12-01 10:15
Memcache is software that might make your Web site go faster. It is a last resort but something you should look at when you use multiple servers.
You can download memcache from memcached.org. They have some documentation in a wiki but a lot of it is just links elsewhere and the links often end at Flash presentations instead of useful pages. For most hosted Web sites, you either do not want memcache or their is an automated way to install memcache without a download.
What does memcache do? Memcache uses spare memory to store unchanged frequently used data so you do not have to drag that data off disk for every page. The key words are spare, unchanged, and frequently.
Spare memory
If you are visiting my site for the first time, you probably do not have spare memory to waste on memcache. Most computers are sold with less than their maximum memory installed. Long term readers of my articles will already know that you buy all your computers, including servers, with the maximum memory. Memcache might then be able to find some spare memory.
Virtual private Server users will not have spare memory because they will be one of 20 or 50 VPSs trying to squeeze into the available memory.
Pageing is an obsolete operating system idea that slows down your computer by trying to substitute disk for memory. If your Web server shows any sign of paging then you do not have enough memory to run memcache.
Your operating system can use memory to cache directories and frequently used files. If your Web site delivers lots of files, you start by allocating enough memory to the operating system so that directories and files are not dragged in from disk for every page access.
PHP can cache code in APC, saving both time and processing cycles. Expand the APC memory until APC does not have to drop current code through lack of memory.
Your database can cache frequently used queries and the results. Give the database all the memory it can effectively use. in many medium size Web sites, the first expansion step is to move the database from the Web server to a separate server so that the database can have more memory. If you are installing memcache before this step, you are wasting memory.
Memcache might be useful here after you have completed all the above memory allocations.
Unchanged data
The advantage of storing data in a database then retrieving the data from the database is the guarantee that the data is current. The database always gives you the latest data based on completed updates. When your database caches the result of a query, your database immediately removes the result from the cache if any of the data is changed. The database query result cache is good. Memcache does not know when the data changes in the database and is a bad alternative to the database result cache.
Memcache might be useful for storing things not retrieved from your database. Suppose you perform financial transactions using an exchange rate extracted from your back. You have a program that runs in the background and visits the bank Web site every minute to get the current exchange rate. You could store the exchange rate in memcache instead of your database. Memcache is good for that type of storage. Memcache does not have to know if the data is current because the background job updates the data in memcache.
Frequently used
Memory is for frequently used data. If something is used on every Web page or every second, store it in memory. If complex data takes three seconds to compute, you want to compute it once per day, not once per Web page. The cutoff point for frequency depends on the resources used to retrieve the data. Compare tow items. Item A takes 10 seconds to retrieve and is used 1 times per minute. Item B requires only 0.01 seconds to retrieve and is used 1000 times per minute. They both chew up 10 seconds per minute and should have equal access to memory.
The Internet is a cache
Web browsers and proxy servers can cache all sorts of files outside of your Web server, including images, CSS, and Javascript. If these files are frequently accessed from your Web site then you need to fix their HTTP headers instead of placing the files in memcache. The HTTP headers tell the Internet how long you want the files cached and a small mistake can result in a file access every page instead of just once every few hours. Memcache is not a substitute for good use of internet and Web browser cache.
A frequently changing file would not be cached out on the Internet and could be stored on disk then cached in memory by the operating system. The same file could be cached in memcache instead. The only difference is the copy on disk. Do you need to write the file to disk? Do you need to read the file after the Web server is switched off? usually you want the file on test when testing a new Web site so you can diagnose faults after the Web site stops. When a site reaches one hundred percent reliability, you do not need the copy on disk and can save the overhead of writing to disk by using memcache.
All of the above
Did your requirement pass all of the above tests? You allocated the maximum useful memory to everything else and still have memory left unused. You do not need a permanent copy of the data. You do not care about the data changing because the change process can update memcache. Memcache is that last thing you look at and it is starting to look good.
When you use cPanel or equivalent, memcache is just an option you tick on one page and it is installed. Lots of hosting companies will put it in when they set up a server for you. Installation is no big deal. The work is in monitoring the memcache memory usage. the ideal is to have one server monitoring page showing memory usage by paging, your operating system, Apache, APC, your database, and memcache then make sure they all have plenty of memory. If any of those services run out, split your Web site across multiple servers.
Multiple servers
Memcache works across multiple servers and shares one copy of each data item. the sharing can be direct in a single box cluster or across the network in a cluster of separate servers. Memcache across a network is slow because the network is the bottleneck. You can have a second network attached to your servers to share memcache data without the network bottleneck but it is still slower than local data and that second network should be dedicated to the database replication required for multiple copies of the database.
If you have memcache shared across several servers, consider using multiple copies of memcache not shared. Consider moving shred data into the database and using the database result cache to share the data at maximum speed. Again, put memcache down the bottom of the list. Look at everything else first.
Go back to the exchange rate example. Think about a Web site running on ten servers. The exchange rate might be used 100 times per second on each server. It is shared from server 1 across the network to the other servers 900 times per second. The exchange rate is retrieved just once per minute from the bank. You could have a separate copy of the exchange rate on every server and update each server just once per minute. The 100 times per second per server would always be retrieved locally. Instead of 900 network accesses every second, there would be just 9 network accesses each minute.
Conclusion
Memcache is easy to abuse and is no substitute for good design, monitoring memory usage, or fast hardware. Use memcache the way you would use chilli in cooking, add it last and in very small amounts.








