jeffotoni / growth

Simples exemplo de CRUD para armazenar em memoria os dados vindo do JSON.
MIT License
44 stars 17 forks source link

Aplica o PHP Swoole #19

Closed wandersonwhcr closed 3 years ago

wandersonwhcr commented 3 years ago

Este PR utiliza a extensão Swoole do PHP para criar um web server com Async IO.

Todas as classes do código fonte foram convertidas para esta extensão. Trocou-se o APCU pelo Swoole\Table.

Para os testes de estresse, utilizou-se o K6 e no script.js removeu-se os comandos de sleep.

running (1m00.0s), 00/10 VUs, 158483 complete and 0 interrupted iterations
default ✓ [ 100% ] 10 VUs  1m0s

     data_received..................: 87 MB  1.4 MB/s
     data_sent......................: 70 MB  1.2 MB/s
     http_req_blocked...............: avg=4.09µs  min=1.17µs   med=2.5µs    max=12.35ms p(90)=3.73µs  p(95)=5.01µs 
     http_req_connecting............: avg=18ns    min=0s       med=0s       max=2.61ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=1.11ms  min=196.11µs med=952.22µs max=36.08ms p(90)=1.84ms  p(95)=2.3ms  
       { expected_response:true }...: avg=1.11ms  min=196.11µs med=952.22µs max=36.08ms p(90)=1.84ms  p(95)=2.3ms  
     http_req_failed................: 0.00%  ✓ 0           ✗ 475449
     http_req_receiving.............: avg=52.71µs min=11.37µs  med=27.08µs  max=28.18ms p(90)=46.36µs p(95)=89.06µs
     http_req_sending...............: avg=21.55µs min=5.97µs   med=13.65µs  max=20.52ms p(90)=21.58µs p(95)=32.26µs
     http_req_tls_handshaking.......: avg=0s      min=0s       med=0s       max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=1.04ms  min=165.84µs med=892.72µs max=35.69ms p(90)=1.75ms  p(95)=2.17ms 
     http_reqs......................: 475449 7923.704607/s
     iteration_duration.............: avg=3.76ms  min=964.14µs med=3.41ms   max=41.52ms p(90)=5.43ms  p(95)=6.6ms  
     iterations.....................: 158483 2641.234869/s
     vus............................: 10     min=10        max=10  
     vus_max........................: 10     min=10        max=10  

Efetuando-se um teste de carga de leitura com ab:

$ ab -n100000 -c1000 http://localhost:8080/api/v1/growth/brz/ngdp_r/2002
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests

Server Software:        swoole-http-server
Server Hostname:        localhost
Server Port:            8080

Document Path:          /api/v1/growth/brz/ngdp_r/2002
Document Length:        67 bytes

Concurrency Level:      1000
Time taken for tests:   14.574 seconds
Complete requests:      100000
Failed requests:        0
Total transferred:      22200000 bytes
HTML transferred:       6700000 bytes
Requests per second:    6861.30 [#/sec] (mean)
Time per request:       145.745 [ms] (mean)
Time per request:       0.146 [ms] (mean, across all concurrent requests)
Transfer rate:          1487.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   37 202.2      1    3051
Processing:     1  100 253.4     34    3064
Waiting:        1   96 253.1     30    3062
Total:          1  137 331.8     36    3298

Percentage of the requests served within a certain time (ms)
  50%     36
  66%     45
  75%     53
  80%     59
  90%    108
  95%   1058
  98%   1088
  99%   1249
 100%   3298 (longest request)

Por fim, o tamanho da imagem Docker aumentou de 2.38MB para 5.26MB.

wandersonwhcr commented 3 years ago

@jeffotoni podes confirmar pra mim se o resultado do K6 está correto? No campo http_req_failed tenho 0% mas tem um caractere de "check" com valor 0.

wandersonwhcr commented 3 years ago

Atualizei a descrição do PR com os resultados do teste de estresse no meu outro notebook.

jeffotoni commented 3 years ago

@wandersonwhcr vou conferir ai..

jeffotoni commented 3 years ago

@wandersonwhcr Man primeiro testamos no Locust, para ver se irá suportar 1000 usuários simultâneos, mas não aguentou .. 😞😞 resultado1 resultado2 resultado3 resultado4

wandersonwhcr commented 3 years ago

Certo.

Os outros projetos tem manual de como buildar as imagens? Eu quero ver se elas aguentam a mesma coisa.

Também acho interessante ter um contrato sobre o que deve aguentar. Não encontrei no código qualquer ponto que solicita um teste com 1000 usuários simultâneos.

wandersonwhcr commented 3 years ago

Por exemplo, o teu teste de K6 define que são 10 usuários virtuais.

Se eu configurar 1000:

default ✓ [ 100% ] 1000 VUs  1m0s

     data_received..................: 87 MB  1.4 MB/s
     data_sent......................: 71 MB  1.2 MB/s
     http_req_blocked...............: avg=337.47µs min=1.15µs   med=2.57µs   max=375.72ms p(90)=3.92µs   p(95)=5.13µs  
     http_req_connecting............: avg=304.1µs  min=0s       med=0s       max=375.61ms p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=121.63ms min=321.3µs  med=110.97ms max=706.42ms p(90)=175.93ms p(95)=225.8ms 
       { expected_response:true }...: avg=121.63ms min=321.3µs  med=110.97ms max=706.42ms p(90)=175.93ms p(95)=225.8ms 
     http_req_failed................: 0.00%  ✓ 0           ✗ 478518
     http_req_receiving.............: avg=1.03ms   min=9.08µs   med=26.93µs  max=381.68ms p(90)=193.33µs p(95)=456.11µs
     http_req_sending...............: avg=214.51µs min=5.2µs    med=13.64µs  max=334.57ms p(90)=39.4µs   p(95)=170.75µs
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=120.37ms min=284.02µs med=110.42ms max=510.67ms p(90)=174.42ms p(95)=222.48ms
     http_reqs......................: 478518 7934.893466/s
     iteration_duration.............: avg=376.15ms min=39.47ms  med=352.68ms max=1.04s    p(90)=535.38ms p(95)=593.66ms
     iterations.....................: 159506 2644.964489/s
     vus............................: 1000   min=1000      max=1000
     vus_max........................: 1000   min=1000      max=1000

Roda tranquilamente.

Vejo que o desafio aumenta cada vez mais que consigo entregar algo funcional.

wandersonwhcr commented 3 years ago

Deixo o desafio para outra pessoa continuar.

Aprendi muito sobre redução de imagens.

Obrigado!

jeffotoni commented 3 years ago

@wandersonwhcr diminuir aqui quantidade de usuários por segundo, e aguentou viu , ficou pau a pau com os outros.. agora sim heeee

php-destruindo

jeffotoni commented 3 years ago

@wandersonwhcr Agora sim, pau a pau ..

php-destruindo

Este resultado aí sem falhas e suportando a porrada....

Ficou muito bom aí a otimização auuauauauau.

jeffotoni commented 3 years ago

@wandersonwhcr rapaz ficou monstrinho o PHP viu..

PHP Swoole ` running (0m30.0s), 000/100 VUs, 298511 complete and 0 interrupted iterations default ✓ [======================================] 100 VUs 30s

 data_received..................: 123 MB 4.1 MB/s
 data_sent......................: 224 MB 7.5 MB/s
 http_req_blocked...............: avg=188.81µs min=41.87µs  med=75.16µs max=52.76ms  p(95)=584.12µs p(99)=2.29ms  p(99.99)=18.62ms count=298511
 http_req_connecting............: avg=133.45µs min=22.64µs  med=49.3µs  max=52.72ms  p(95)=472.84µs p(99)=1.7ms   p(99.99)=14.99ms count=298511
 http_req_duration..............: avg=9.51ms   min=306.2µs  med=9.34ms  max=97.53ms  p(95)=13.16ms  p(99)=17.93ms p(99.99)=81.7ms  count=298511
   { expected_response:true }...: avg=9.51ms   min=306.2µs  med=9.34ms  max=97.53ms  p(95)=13.16ms  p(99)=17.93ms p(99.99)=81.7ms  count=298511
 http_req_failed................: 0.00%  ✓ 0           ✗ 298511
 http_req_receiving.............: avg=401.71µs min=13.82µs  med=56.66µs max=20.25ms  p(95)=2.22ms   p(99)=5.33ms  p(99.99)=14.84ms count=298511
 http_req_sending...............: avg=179.2µs  min=11.54µs  med=31.08µs max=52.88ms  p(95)=737.75µs p(99)=3.21ms  p(99.99)=18.88ms count=298511
 http_req_tls_handshaking.......: avg=0s       min=0s       med=0s      max=0s       p(95)=0s       p(99)=0s      p(99.99)=0s      count=298511
 http_req_waiting...............: avg=8.93ms   min=111.84µs med=9.2ms   max=97.06ms  p(95)=11.24ms  p(99)=14.07ms p(99.99)=79.65ms count=298511
 http_reqs......................: 298511 9947.456266/s
 iteration_duration.............: avg=10.03ms  min=871.8µs  med=9.68ms  max=137.15ms p(95)=14.1ms   p(99)=19.02ms p(99.99)=84.32ms count=298511
 iterations.....................: 298511 9947.456266/s
 vus............................: 100    min=100       max=100 
 vus_max........................: 100    min=100       max=100`

EM C ` running (0m30.0s), 000/100 VUs, 359889 complete and 0 interrupted iterations default ✓ [======================================] 100 VUs 30s

 data_received..................: 258 MB 8.6 MB/s
 data_sent......................: 270 MB 9.0 MB/s
 http_req_blocked...............: avg=204.35µs min=38.88µs  med=78.88µs max=41.45ms p(95)=589.64µs p(99)=2.59ms  p(99.99)=21.05ms count=359889
 http_req_connecting............: avg=155.06µs min=23.82µs  med=52.03µs max=41.05ms p(95)=513.38µs p(99)=1.88ms  p(99.99)=20.72ms count=359889
 http_req_duration..............: avg=7.77ms   min=106.59µs med=3.4ms   max=97.35ms p(95)=26.93ms  p(99)=39.34ms p(99.99)=67.53ms count=359889
   { expected_response:true }...: avg=7.77ms   min=106.59µs med=3.4ms   max=97.35ms p(95)=26.93ms  p(99)=39.34ms p(99.99)=67.53ms count=359889
 http_req_failed................: 0.00%  ✓ 0            ✗ 359889
 http_req_receiving.............: avg=428.17µs min=11.89µs  med=75.48µs max=33.91ms p(95)=1.96ms   p(99)=5.94ms  p(99.99)=20.09ms count=359889
 http_req_sending...............: avg=205.46µs min=10.96µs  med=39.2µs  max=34.47ms p(95)=790.29µs p(99)=3.15ms  p(99.99)=18.24ms count=359889
 http_req_tls_handshaking.......: avg=0s       min=0s       med=0s      max=0s      p(95)=0s       p(99)=0s      p(99.99)=0s      count=359889
 http_req_waiting...............: avg=7.14ms   min=42.89µs  med=2.6ms   max=97.28ms p(95)=26ms     p(99)=38.4ms  p(99.99)=67.31ms count=359889
 http_reqs......................: 359889 11992.748044/s
 iteration_duration.............: avg=8.32ms   min=281.29µs med=4.06ms  max=97.55ms p(95)=27.6ms   p(99)=40.15ms p(99.99)=69.97ms count=359889
 iterations.....................: 359889 11992.748044/s
 vus............................: 99     min=99         max=100 
 vus_max........................: 100    min=100        max=100 

EM GO default ✓ [======================================] 100 VUs 30s

 data_received..................: 41 MB  1.4 MB/s
 data_sent......................: 227 MB 7.5 MB/s
 http_req_blocked...............: avg=9.94µs   min=741ns    med=1.81µs  max=28.43ms  p(95)=3.37µs   p(99)=8.43µs   p(99.99)=27.24ms count=301979
 http_req_connecting............: avg=6.11µs   min=0s       med=0s      max=28.39ms  p(95)=0s       p(99)=0s       p(99.99)=27.21ms count=301979
 http_req_duration..............: avg=9.25ms   min=166.61µs med=8.34ms  max=120.68ms p(95)=19.77ms  p(99)=31.42ms  p(99.99)=95.19ms count=301979
   { expected_response:true }...: avg=9.25ms   min=166.61µs med=8.34ms  max=120.68ms p(95)=19.77ms  p(99)=31.42ms  p(99.99)=95.19ms count=301979
 http_req_failed................: 0.00%  ✓ 0            ✗ 301979
 http_req_receiving.............: avg=114.01µs min=7.64µs   med=19.78µs max=33.24ms  p(95)=156.65µs p(99)=2.24ms   p(99.99)=21.5ms  count=301979
 http_req_sending...............: avg=36.12µs  min=4.73µs   med=10.55µs max=35.63ms  p(95)=39.77µs  p(99)=166.46µs p(99.99)=17.94ms count=301979
 http_req_tls_handshaking.......: avg=0s       min=0s       med=0s      max=0s       p(95)=0s       p(99)=0s       p(99.99)=0s      count=301979
 http_req_waiting...............: avg=9.1ms    min=144.02µs med=8.26ms  max=98.63ms  p(95)=19.49ms  p(99)=29.23ms  p(99.99)=94.95ms count=301979
 http_reqs......................: 301979 10061.169251/s
 iteration_duration.............: avg=9.91ms   min=329.87µs med=8.9ms   max=125.59ms p(95)=21.17ms  p(99)=32.49ms  p(99.99)=98.27ms count=301979
 iterations.....................: 301979 10061.169251/s
 vus............................: 86     min=86         max=100 
 vus_max........................: 100    min=100        max=100 

`