Go baakanngwa ga tiragatso
Tiro ya tiragatso e tshwanetse go simolola ka go lekanya. Batla llaga e e bonya go gaisa, e baakanye, mme o lekanye gape. Bontsi jwa dithibelo tsa go amogela ke nngwe ya: PHP go bolawa, dipotso tsa polokelotshedimosetso, dithoto tse di sa fetogeng tse di sa bolokwang kgotsa memori o o sa lekanang.
Lekanya pele
# Response time and status
curl -o /dev/null -s -w "dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n" https://app.example.com
# Server load and memory
uptime
free -m
vmstat 1 5
# Top processes
ps aux --sort=-%cpu | head -10
ps aux --sort=-%mem | head -10Dintlha tse phahameng tsa TTFB ho PHP kapa polokelotshedimosetso. Palogotlhe e e kwa godimo e e nang le dintlha tse di kwa tlase tsa TTFB ka bogolo jwa morwalo wa tuelo kgotsa dithoto tsa letlhakore la tlelaente.
PHP le OPcache
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=2Mo tlhagisong, netefatsa ditempe tsa nako ka sewelo kgotsa thibela netefatso mme o phimole OPcache fa e dirisiwa. Tlhomamisa gore polokelotlaleletso e dirisitswe tota:
php -i | grep opcache<?php
$status = opcache_get_status();
echo $status['opcache_statistics']['opcache_hit_rate'];Bogolo jwa PHP-FPM
pm = dynamic
pm.max_children = 24
pm.start_servers = 6
pm.min_spare_servers = 4
pm.max_spare_servers = 12
pm.max_requests = 500Bogolo jwa max_children go tswa mo mogopolong, e seng go fopholetsa:
available_ram_mb / average_php_process_mb = max_childrenLekanya thulaganyo ya palogare ka ps -o rss= -C php-fpm8.3 | awk '{s+=$1} END {print s/NR/1024" MB"}'. Tlogela sebaka sa tlhogo sa OS, polokelotshedimosetso le sefara ya webo.
Polokelotshedimosetso
| Thekeniki | Dira |
|---|---|
| Ditshupane mo dikholomo tsa setlhotlhi le tsa go kopanya | Phenyo e kgolo go di feta tsotlhe |
EXPLAIN mo dipotsong tse di bonya | E senola ditshwantsho ka botlalo |
Tila SELECT * | I/O e nnye le memori |
| Dikgolagano tse di tswelelang | Go tshwarana ka diatla go le mmalwa, ditekanyetso tsa kgolagano ya tshupanako |
| Batsa polokelotshedimosetso mo llageng ya tiriswa | O tlola tiro e e boaboelediwang |
EXPLAIN ANALYZE
SELECT id, total FROM orders
WHERE customer_id = 1042 AND status = 'paid'
ORDER BY created_at DESC
LIMIT 20;Fa leano le bontsha sekene se se tletseng, tsenya tshupane e e kopantsweng mo (customer_id, status, created_at).
Go boloka dillaga
Browser cache → CDN / edge → page cache → object cache → OPcache → database| Tlhatlhagano | Se o tshwanetseng go se boloka | TTL e e tlwaelegileng |
|---|---|---|
| Sebatli | Ditshwantsho, difonte, CSS, JS | Ngwaga o le 1, kgatiso ya menwana |
| WFP0X | Dithoto tse di sa fetogeng, ditsebe tsa botlhe | Letsatsi le le 1 |
| Polokelotlaleletso ya tsebe | HTML e e feletseng ya badirisi ba ba sa itsiweng | Metsotso e le 5–60 |
| Polokelotlaleletso ya dilo | Dipholo tsa patlisiso, dithulaganyo | Metsotso e le 5–30 |
| WFP0X | E kokoantswe PHP | Go fitlha go romelwa |
Dira gore o se ka wa dira ka boomo. Polokelotshedimosetso e e senang leano la go dira gore e se ka ya dira e nna khukhwana ya go nepagala.
Dithoto tse di sa fetogeng le HTTP
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_min_length 1024;
location ~* \.(css|js|woff2|png|jpg|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}Kgontsha HTTP/2 kwa ntlheng le HTTP/3 fa e tshegediwang teng. Maina a difaele tsa letlotlo la kgatiso ya menwana ka jalo matshelo a polokelotshedimosetso a maleele a babalesegile.
Ditshwantsho le metswedi ya dikgang
- Direla difomate tsa segompieno (WebP/AVIF) ka go boela morago.
- Fetola bogolo ka nako ya go laisa, e seng mo kopong nngwe le nngwe.
- Ditshwantsho tse di laisitsweng ka fa tlase ga mena.
- Laisa metswedi ya dikgang e megolo mo polokelong ya dilo le CDN.
Diphethene tsa pharakano
| Sekao | Letshwao | Tiragalo |
|---|---|---|
| CPU e e kwa godimo e e tlhomameng | PHP ga e dire sentle | Porofaele ya tsela e e botlhokwa, tsenya OPcache |
| CPU e e nang le dintlha | Ditsebe tse di sa bolokwang | Tsenya polokelotshedimosetso ya tsebe |
| Memori e e kwa godimo | Badiri ba bantsi thata | Fokotsa max_children |
| Dipatlisiso tse di bonya | Polokelotshedimosetso e e bofilweng | Tshupane, o bo o tokafatsa sekema |
| Bophara jwa bente jo bo kwa godimo | Dithoto tse dikgolo | Gatelela, CDN, morwalo wa botshwakga |
Go ela tlhoko
Latedisa p50, p95 le p99 tiego go na le dipalogare. Tlhagiso ka dipoelo tsa p95, seelo sa phoso le go tlala. Boloka motheo wa pharakano e e tlwaelegileng gore phetogo e bonale pele ga badirisi ba e bega.
Lenaanenetefatso
- [ ] OPcache e kgontshitswe mme selekanyo sa go itewa se kwa godimo
- [ ] Badiri ba PHP-FPM ba lekanyeditswe go tswa mo mogopolong o o lekanyeditsweng
- [ ] Pego ya dipatlisiso e e bonya e sekasekwa beke le beke
- [ ] Dithoto tse di sa fetogeng di gatisitswe menwana le go bolokwa mo polokelotshedimosetsong lobaka lwa ngwaga
- [ ] CDN kgotsa polokelotshedimosetso ya pharakano ya botlhe
- [ ] go diega ga ts95 le selekanyo sa diphoso di tsibositswe
- [ ] Teko ya morwalo morago ga diphetogo tse dikgolo