Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL & Expression Engine EEUK2013


Published on

EEvolution slides from EEUK2013 to use as a reference to our talk. Let us know if you need a hand with anything or further explanation... we know it was quite a heavy presentation.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

MySQL & Expression Engine EEUK2013

  1. 1. EEUK2013MySQL &ExpressionEngine
  2. 2. Why EEvolution?We believe that system efficiency is #1 asits the root to saving time and costsWe provide cost effective solutions thathave a return on investmentWe create software to solve problems
  3. 3. Sound Familiar?- Why is my site is slow?- How can I get better performance?- What if I get an increase in visitors?- Search bots are killing my server!The database is the data store of your site... but what can you do to get the best out of it?DESIGN FOR PERFORMANCE & SCALE
  4. 4. Hardware: PlatformCost Performance ReliabilityShared Low Low MediumVPS Low Low / Variable MediumCloud Medium Medium Very HighDynamic Cloud Medium / PAYG Medium Very HighDedicated High Very High HighPrivate Cloud Very High High Very High
  5. 5. Hardware: CPUCores (40%)- Single, Dual, Quad, Six, HexClock Speed (30%)- 2ghz, 3ghz, 4ghzVendor (20%)- AMD vs IntelCPUs (10%)- Single vs Dual
  6. 6. Hardware: Memory25% of Server Memory should cover DatabaseIndexes (not data in MyISAM)- key_buffer_size = 25%-35% server memory- PHPMyAdmin -> Status gives you a easy toread analysis and config recommendation.- Check RAM benchmarks when purchasing aserver
  7. 7. Hardware: DiskIOPS & Random Reads- SATA (75- 150)- SAS (140 - 210)- SSD (9,000 - 10,000,000)- RAMDisk (30,000 - 50,000, use with caution!)Hard disks need a good controller which is alsoan important factor for performance.Never mix disk types in a RAID
  8. 8. Operating SystemBackground ProcessesLinux (LAMP, cPanel, Plesk, Webmin)- CentOSWindows (WAMP)- Windows XP- Windows 7- Server 2008 + Core Mode- Server 2012 + Core Mode
  9. 9. IndexesSELECT = ReadINSERT, UPDATE, DELETE = Read/Write- Writes will always force an index update.- Only index columns that you will JOIN ON oruse in WHERE and ORDER BY.- Schedule an auto DB optimisation.- EE thottling has a big impact on DB writes- Index files can be stored on a different disk.
  10. 10. Views, Stored Procedures,Functions- VIEWS are used for organisation not forperformance. They can improve speed due toreduced lock times on large datasets.- STORED PROCEDURES are used fororganisation not for performance. Dont give upthe dynamically created statement for the bestpractice itll cost you in time.- FUNCTIONS are used for organisation not forperformance. Stay away, you will only slowdown your queries and waste time.
  11. 11. Optimisation MaintenanceAutomatically optimise your database with afrequently run Cron or Scheduled Task- Tuning Primer Script- MySQL Tuning ScriptDont forget to email yourself the results.
  12. 12. BackupMaster / Slave, Replication- Backup, Distribution- Read only, Analysis (RAMDisk)Clustering, RAID- Resilience, Automatic FailoverCron / Scheduled Task- Custom Script, perhaps Amazon S3WHM- Scheduled Offsite Backup
  13. 13. So... were firing on all cylinders!Remember:- Get best value hardware for your budget- Configure for the correct situation- Use PHPMyAdmin Status & Tuning Script- Ensure Backup / Replication / Resilience... Just in case, but always a must!NOW LETS LOOK AT EE...
  14. 14. EE Settings- Disable what you dont need- Page, Template, DB, Tag Cache- Config: Disable Tracking
  15. 15. Query CacheEE Dynamic Query Cache:- If you do not use future entries, expiringentries and random entries turn this on.- MySQL also has a cache mechanism whichcan improve performance by +200% whenretrieving data from tables that do not changeoften. In general it has a 13% overhead. Setquery_cache_size between 10MB and 150MB(avg size of query results * number of queries)
  16. 16. SchemaEE Schema- Entry data is wide not deep for scalability.- Relationships are centralised for simplicity.- Follow true relationships on your addons forbest performance.- Index columns based on EE SQL Debugresults. e.g. Searchable custom fields. Dontassume the schema is 100% efficient out of thebox for EE or third party addons.
  17. 17. Pre-calculated fieldsDo on-the-fly calculations in a dedicated fieldbased on triggered events- Total number of sales- Total revenue per member- Total entry count per member or category- Run a sanity check/update when idle toensure this is accurate regularly.- Gives you the flexibility to COUNT (accurate,latency) or SELECT (possibly inaccurate,
  18. 18. EE Entry DB StructureGet Entries From Table - {exp:query sql=""}SELECT *, t.*, t.entry_id, COUNT(DISTINCT p.cat_name) AS distinct_count, CASE WHEN IFNULL(NULLIF(field_id_15,),none)=none THEN field_id_16 ELSE field_id_15 END AS choiceFROM exp_channel_titles tINNER JOIN exp_channel_data d ON d.entry_id = t.entry_idINNER JOIN exp_members m ON m.member_id = t.author_idINNER JOIN exp_member_groups mg ON mg.group_id = m.group_idINNER JOIN exp_member_data md ON md.member_id = m.member_idLEFT OUTER JOIN exp_category_posts p ON p.entry_id = t.entry_idLEFT OUTER JOIN exp_categories c ON c.cat_id = p.cat_idLEFT OUTER JOIN exp_category_field_data cfd ON cfd.cat_id = c.cat_idWHERE t.status=open OR t.entry_id = (0{entry_id}) OR t.entry_id IN (0{preload_replace_vars}) OR t.entry_id IN (0{snippet_var}) OR p.cat_url_title = {segment_3} OR d.field_id_16 LIKE test% OR t.entry_date > UNIX_TIMESTAMP(2013-05-16 00:00:00) OR d.field_id_16 = d.field_id_17 OR t.entry_id IN ({snippet_subquery_chosen_categories})ORDER BY t.entry_date DESCGROUP BY t.entry_id HAVING COUNT(p.cat_name) > 2
  19. 19. SummaryRemember:- Use this document as a reference- Plan your system resources, configureappropriately and use EE Debug Tools- Dont be afraid to use {exp:query} to get whatyou need.- Contact us if you need assistance in hardwareor database decisions, optimisation or adviceon your system... were here to help.
  20. 20. Thank You !Any Questions?Tim MahoneyEEvolution