Optimasi Kinerja
XOOPS Optimasi Kinerja
Section titled “XOOPS Optimasi Kinerja”Panduan komprehensif untuk mengoptimalkan XOOPS untuk kecepatan dan efisiensi maksimum.
Ikhtisar Pengoptimalan Kinerja
Section titled “Ikhtisar Pengoptimalan Kinerja”graph TD A[Performance] --> B[Caching] A --> C[Database] A --> D[Web Server] A --> E[front-end] A --> F[Code] B --> B1[Page Cache] B --> B2[Query Cache] B --> B3[Template Cache] C --> C1[Indexes] C --> C2[Queries] C --> C3[Optimization] D --> D1[Compression] D --> D2[Headers] D --> D3[Connection] E --> E1[Images] E --> E2[CSS/JS] E --> E3[Lazy Load] F --> F1[Modules] F --> F2[Queries]Konfigurasi Caching
Section titled “Konfigurasi Caching”Caching adalah cara tercepat untuk meningkatkan kinerja.
Caching Tingkat Halaman
Section titled “Caching Tingkat Halaman”Aktifkan cache halaman penuh di XOOPS:
Panel Admin > Sistem > Preferensi > Pengaturan Cache
Enable Caching: YesCache Type: File Cache (or APCu/Memcache)Cache Lifetime: 3600 seconds (1 hour)Cache Module Lists: YesCache Configuration: YesCache Search Results: YesCaching Berbasis File
Section titled “Caching Berbasis File”Konfigurasikan lokasi cache file:
# Create cache directory outside web root (more secure)mkdir -p /var/cache/xoopschown www-data:www-data /var/cache/xoopschmod 755 /var/cache/xoops
# Edit mainfile.phpdefine('XOOPS_CACHE_PATH', '/var/cache/xoops/');Penembolokan APCu
Section titled “Penembolokan APCu”APCu menyediakan cache dalam memori (sangat cepat):
# Install APCuapt-get install php-apcu
# Verify installationphp -m | grep apcu
# Configure in php.iniapc.enabled = 1apc.memory_size = 128Mapc.ttl = 0apc.user_ttl = 3600apc.shm_size = 128Aktifkan di XOOPS:
Panel Admin > Sistem > Preferensi > Pengaturan Cache
Cache Type: APCuPenembolokan Memcache/Redis
Section titled “Penembolokan Memcache/Redis”Caching terdistribusi untuk situs dengan lalu lintas tinggi:
Instal Memcache:
# Install Memcache serverapt-get install memcached
# Start servicesystemctl start memcachedsystemctl enable memcached
# Verify runningnetstat -tlnp | grep memcached# Should show listening on port 11211Konfigurasi di XOOPS:
Sunting mainfile.php:
// Memcache configurationdefine('XOOPS_CACHE_TYPE', 'memcache');define('XOOPS_CACHE_HOST', 'localhost');define('XOOPS_CACHE_PORT', 11211);define('XOOPS_CACHE_TIMEOUT', 0);Atau di panel admin:
Cache Type: MemcacheMemcache Host: localhost:11211Penyimpanan template
Section titled “Penyimpanan template”Kompilasi dan cache template XOOPS:
# Ensure templates_c is writablechmod 777 /var/www/html/xoops/templates_c/
# Clear old cached templatesrm -rf /var/www/html/xoops/templates_c/*Konfigurasikan dalam theme:
<!-- In theme xoops_version.php -->{smarty.const.XOOPS_VAR_PATH|constant}<{$xoops_meta}>
<!-- Templates use caching -->{cache} [Cached content here]{/cache}Optimasi Basis Data
Section titled “Optimasi Basis Data”Tambahkan Indeks Basis Data
Section titled “Tambahkan Indeks Basis Data”Basis data yang diindeks dengan benar membuat kueri lebih cepat.
-- Check current indexesSHOW INDEXES FROM xoops_users;
-- Common indexes to addALTER TABLE xoops_users ADD INDEX idx_uname (uname);ALTER TABLE xoops_users ADD INDEX idx_email (email);ALTER TABLE xoops_users ADD INDEX idx_uid_active (uid, user_actkey);
-- Add indexes to posts/content tablesALTER TABLE xoops_posts ADD INDEX idx_post_published (post_published);ALTER TABLE xoops_posts ADD INDEX idx_post_uid (post_uid);ALTER TABLE xoops_posts ADD INDEX idx_post_created (post_created);
-- Verify indexes createdSHOW INDEXES FROM xoops_users\GOptimalkan Tabel
Section titled “Optimalkan Tabel”Pengoptimalan tabel reguler meningkatkan kinerja:
-- Optimize all tablesOPTIMIZE TABLE xoops_users;OPTIMIZE TABLE xoops_posts;OPTIMIZE TABLE xoops_config;OPTIMIZE TABLE xoops_comments;
-- Or optimize all at onceREPAIR TABLE xoops_users;OPTIMIZE TABLE xoops_users;REPAIR TABLE xoops_posts;OPTIMIZE TABLE xoops_posts;Buat skrip pengoptimalan otomatis:
#!/bin/bash# Database optimization script
echo "Optimizing XOOPS database..."
mysql -u xoops_user -p xoops_db << EOF-- Optimize all tablesOPTIMIZE TABLE xoops_users;OPTIMIZE TABLE xoops_posts;OPTIMIZE TABLE xoops_config;OPTIMIZE TABLE xoops_comments;OPTIMIZE TABLE xoops_users_online;
-- Show database sizeSELECT table_schema, ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) as total_mbFROM information_schema.tablesWHERE table_schema = 'xoops_db'GROUP BY table_schema;EOF
echo "Database optimization completed!"Jadwalkan dengan cron:
# Weekly optimizationcrontab -e# Add: 0 3 * * 0 /usr/local/bin/optimize-xoops-db.shOptimasi Kueri
Section titled “Optimasi Kueri”Tinjau kueri yang lambat:
-- Enable slow query logSET GLOBAL slow_query_log = 'ON';SET GLOBAL long_query_time = 2;
-- View slow queriesSELECT * FROM mysql.slow_log;
-- Or check slow log filetail -100 /var/log/mysql/slow.logTeknik optimasi umum:
// SLOW - Avoid unnecessary queries in loopsforeach ($users as $user) { $profile = getUserProfile($user['uid']); // Query in loop! echo $profile['name'];}
// FAST - Get all data at once$profiles = getAllUserProfiles($user_ids);foreach ($users as $user) { echo $profiles[$user['uid']]['name'];}Meningkatkan Kumpulan Buffer
Section titled “Meningkatkan Kumpulan Buffer”Konfigurasikan MySQL untuk caching yang lebih baik:
Sunting /etc/mysql/mysql.conf.d/mysqld.cnf:
# InnoDB Buffer Pool (50-80% of system RAM)innodb_buffer_pool_size = 1G
# Query Cache (optional, can be disabled in MySQL 5.7+)query_cache_size = 64Mquery_cache_type = 1
# Max Connectionsmax_connections = 500
# Max Allowed Packetmax_allowed_packet = 256M
# Connection timeoutconnect_timeout = 10Mulai ulang MySQL:
systemctl restart mysqlOptimasi Server Web
Section titled “Optimasi Server Web”Aktifkan Kompresi Gzip
Section titled “Aktifkan Kompresi Gzip”Kompres respons untuk mengurangi bandwidth:
Konfigurasi Apache:
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
# Don't compress images and already compressed files SetEnvIfNoCase Request_URI \.(jpg|jpeg|png|gif|zip|gzip)$ no-gzip dont-vary
# Log compressed responses DeflateBufferSize 8096</IfModule>Konfigurasi Nginx:
gzip on;gzip_types text/html text/plain text/css text/javascript application/javascript application/json;gzip_min_length 1000;gzip_vary on;gzip_comp_level 6;
# Don't compress already compressed formatsgzip_disable "msie6";Verifikasi kompresi:
# Check if response is gzippedcurl -I -H "Accept-Encoding: gzip" http://your-domain.com/xoops/
# Should show:# Content-Encoding: gzipHeader Caching Browser
Section titled “Header Caching Browser”Tetapkan masa berlaku cache untuk aset statis:
Apache:
<IfModule mod_expires.c> ExpiresActive On
# Cache images for 30 days ExpiresByType image/jpeg "access plus 30 days" ExpiresByType image/gif "access plus 30 days" ExpiresByType image/png "access plus 30 days" ExpiresByType image/svg+xml "access plus 30 days"
# Cache CSS/JS for 30 days ExpiresByType text/css "access plus 30 days" ExpiresByType application/javascript "access plus 30 days" ExpiresByType text/javascript "access plus 30 days"
# Cache fonts for 1 year ExpiresByType font/eot "access plus 1 year" ExpiresByType font/ttf "access plus 1 year" ExpiresByType font/woff "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year"
# Don't cache HTML ExpiresByType text/html "access plus 1 hour"</IfModule>Nginx:
location ~* \.(jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 30d; add_header Cache-Control "public, immutable";}
location ~* \.(css|js)$ { expires 30d; add_header Cache-Control "public";}
location ~ \.html$ { expires 1h; add_header Cache-Control "public";}Koneksi Tetap Hidup
Section titled “Koneksi Tetap Hidup”Aktifkan koneksi HTTP persisten:
Apache:
<IfModule mod_http.c> KeepAlive On KeepAliveTimeout 15 MaxKeepAliveRequests 100</IfModule>Nginx:
keepalive_timeout 15s;keepalive_requests 100;Optimasi Bagian Depan
Section titled “Optimasi Bagian Depan”Optimalkan Gambar
Section titled “Optimalkan Gambar”Kurangi ukuran file gambar:
# Batch compress JPEG imagesfor img in *.jpg; do convert "$img" -quality 85 "optimized_$img"done
# Batch compress PNG imagesfor img in *.png; do optipng -o2 "$img"done
# Or use imagemin CLInpm install -g imagemin-cliimagemin images/ --out-dir=images-optimizedPerkecil CSS dan JavaScript
Section titled “Perkecil CSS dan JavaScript”Kurangi ukuran file CSS/JS:
Menggunakan alat Node.js:
# Install minifiersnpm install -g uglify-js clean-css-cli
# Minify JavaScriptuglifyjs script.js -o script.min.js
# Minify CSScleancss style.css -o style.min.cssMenggunakan alat online:
- CSS Pengurang: https://cssminifier.com/
- JavaScript Pengurang: https://www.minifycode.com/javascript-minifier/
Malas Memuat Gambar
Section titled “Malas Memuat Gambar”Muat gambar hanya bila diperlukan:
<!-- Add loading="lazy" attribute --><img src="image.jpg" alt="Description" loading="lazy">
<!-- Or use JavaScript library for older browsers --><img class="lazy" src="placeholder.jpg" data-src="image.jpg" alt="Description">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/17.1.2/lazyload.min.js"></script><script> var lazyLoad = new LazyLoad({ elements_selector: ".lazy" });</script>Kurangi Sumber Daya yang Memblokir Render
Section titled “Kurangi Sumber Daya yang Memblokir Render”Muat CSS/JS secara strategis:
<!-- Load critical CSS inline --><style> /* Critical styles for above-the-fold */</style>
<!-- Defer non-critical CSS --><link rel="stylesheet" href="style.css" media="print" onload="this.media='all'">
<!-- Defer JavaScript --><script src="script.js" defer></script>
<!-- Or use async for non-critical scripts --><script src="analytics.js" async></script>Integrasi CDN
Section titled “Integrasi CDN”Gunakan Jaringan Pengiriman Konten untuk akses global yang lebih cepat.
CDN Populer
Section titled “CDN Populer”| CDN | Biaya | Fitur |
|---|---|---|
| awan suar | Free/Paid | DDoS, DNS, Cache, Analisis |
| AWS CloudFront | Berbayar | Performa tinggi, global |
| Kelinci CDN | Terjangkau | Penyimpanan, video, cache |
| jsDelivr | Gratis | Perpustakaan JavaScript |
| cdnjs | Gratis | Perpustakaan populer |
Pengaturan Cloudflare
Section titled “Pengaturan Cloudflare”-
Daftar di https://www.cloudflare.com/
-
Tambahkan domain Anda
-
Perbarui server nama dengan Cloudflare
-
Aktifkan opsi cache:
- Tingkat Cache: Agresif
- Menyimpan cache pada semuanya: Aktif
- TTL Caching Browser: 1 bulan
-
Di XOOPS, perbarui domain Anda untuk menggunakan Cloudflare DNS
Konfigurasikan CDN di XOOPS
Section titled “Konfigurasikan CDN di XOOPS”Perbarui URL gambar ke CDN:
Edit template theme:
<!-- Original --><img src="{$xoops_url}/uploads/image.jpg" alt="">
<!-- With CDN --><img src="https://cdn.your-domain.com/uploads/image.jpg" alt="">Atau atur di PHP:
// In mainfile.php or configdefine('XOOPS_CDN_URL', 'https://cdn.your-domain.com');
// In template<img src="{$smarty.const.XOOPS_CDN_URL}/uploads/image.jpg" alt="">Pemantauan Kinerja
Section titled “Pemantauan Kinerja”Pengujian Wawasan PageSpeed
Section titled “Pengujian Wawasan PageSpeed”Uji kinerja situs Anda:
- Kunjungi Google PageSpeed Insights: https://pagespeed.web.dev/
- Masukkan XOOPS URL Anda
- Tinjau rekomendasi
- Melaksanakan perbaikan yang disarankan
Pemantauan Kinerja Server
Section titled “Pemantauan Kinerja Server”Pantau metrik server waktu nyata:
# Install monitoring toolsapt-get install htop iotop nethogs
# Monitor CPU and memoryhtop
# Monitor disk I/Oiotop
# Monitor networknethogsProfil Kinerja PHP
Section titled “Profil Kinerja PHP”Identifikasi kode PHP yang lambat:
<?php// Use Xdebug for profilingxdebug_start_trace('profile');
// Your code here$result = someExpensiveFunction();
xdebug_stop_trace();?>Pemantauan Kueri MySQL
Section titled “Pemantauan Kueri MySQL”Lacak kueri lambat:
# Enable query loggingmysql -u root -p
SET GLOBAL general_log = 'ON';SET GLOBAL log_output = 'FILE';SET GLOBAL general_log_file = '/var/log/mysql/query.log';
# Review slow queriestail -f /var/log/mysql/slow.log
# Analyze query with EXPLAINEXPLAIN SELECT * FROM xoops_users WHERE uid = 1\GDaftar Periksa Pengoptimalan KinerjaTerapkan ini untuk kinerja terbaik:
Section titled “Daftar Periksa Pengoptimalan KinerjaTerapkan ini untuk kinerja terbaik:”- Caching: Aktifkan cache file/APCu/Memcache
- Database: Tambahkan indeks, optimalkan tabel
- Kompresi: Aktifkan kompresi Gzip
- Cache Browser: Menyetel header cache
- Gambar: Optimalkan dan kompres
- CSS/JS: Perkecil file
- Pemuatan Lambat: Implementasi untuk gambar
- CDN: Digunakan untuk aset statis
- Keep-Alive: Mengaktifkan koneksi persisten
- module: Nonaktifkan module yang tidak digunakan
- theme: Gunakan theme ringan dan optimal
- Pemantauan: Melacak metrik kinerja
- Pemeliharaan Reguler: Hapus cache, optimalkan DB
Skrip Pengoptimalan Kinerja
Section titled “Skrip Pengoptimalan Kinerja”Pengoptimalan otomatis:
#!/bin/bash# Performance optimization script
echo "=== XOOPS Performance Optimization ==="
# Clear cacheecho "Clearing cache..."rm -rf /var/www/html/xoops/cache/*rm -rf /var/www/html/xoops/templates_c/*
# Optimize databaseecho "Optimizing database..."mysql -u xoops_user -p xoops_db << EOFOPTIMIZE TABLE xoops_users;OPTIMIZE TABLE xoops_posts;OPTIMIZE TABLE xoops_config;OPTIMIZE TABLE xoops_comments;EOF
# Check file permissionsecho "Verifying file permissions..."find /var/www/html/xoops -type f -exec chmod 644 {} \;find /var/www/html/xoops -type d -exec chmod 755 {} \;chmod 777 /var/www/html/xoops/cachechmod 777 /var/www/html/xoops/templates_cchmod 777 /var/www/html/xoops/uploadschmod 777 /var/www/html/xoops/var
# Generate performance reportecho "Performance Optimization Complete!"echo ""echo "Next steps:"echo "1. Test site at https://pagespeed.web.dev/"echo "2. Monitor performance in admin panel"echo "3. Consider CDN for static assets"echo "4. Review slow queries in MySQL"Metrik Sebelum dan Sesudah
Section titled “Metrik Sebelum dan Sesudah”Lacak peningkatan:
Before Optimization:- Page Load Time: 3.5 seconds- Database Queries: 45- Cache Hit Rate: 0%- Database Size: 250MB
After Optimization:- Page Load Time: 0.8 seconds (77% faster)- Database Queries: 8 (cached)- Cache Hit Rate: 85%- Database Size: 120MB (optimized)Langkah Selanjutnya
Section titled “Langkah Selanjutnya”- Tinjau konfigurasi dasar
- Pastikan langkah-langkah keamanan
- Menerapkan cache
- Pantau kinerja dengan alat
- Sesuaikan berdasarkan metrik
Tag: #kinerja #optimisasi #caching #database #cdn
Artikel Terkait:
- ../../06-Publisher-Module/User-Guide/Basic-Configuration
- Pengaturan Sistem
- Konfigurasi Keamanan
- ../Installation/Server-Requirements