Hrozně pomalé Apitte oproti Nette sandboxu

Polki
Člen | 553
+
+2
-

Ahoj, běžně si dělám řešení pro své API v Nette.

Řekl jsem si ale, že bych mohl konečně vyzkoušet knihovnu Apitte, protože je dělaná jen pro API, takže mi přišlo logické, že když chci dělat čisté API, tak nemusím používat Nette router, Latte apod. knihovny.

Nainstaloval jsem si tedy čisté Apitte a vrhl se do testování.
Udělal jsem si metodu pro získávání dat metodou GET.

/**
 * @Path("/{name}")
 * @Method("GET")
 * @RequestParameters({
 * 		@RequestParameter(name="name", type="string", description="My favourite chips brand")
 * })
 */
 public function detail(ApiRequest $request): array
 {
     return ['chips' => [
         'id' => 23,
         'nameAttribute' => $request->getAttribute('name'),
         'nameParameter' => $request->getParameter('name'),
         'description' => 'Moje oblibene chrumkave bramburky. Mňamky.',
     ]];
 }

a pak vedle v projektu jsem si udělal funkci v mém řešení v Nette sandboxu:

public function detail(string $name): array
{
    $this->checkMethod($this->getHttpRequest()::GET);

    $this->sendJson(['chips' => [
        'id' => 23,
        'nameAttribute' => $name,
        'nameParameter' => $name,
        'description' => 'Moje oblibene chrumkave bramburky. Mňamky.',
    ]]);
}

public function checkMethod(string $method): void
{
    if ($this->request->isMethod($method)) {
        return;
    }

    $this->getHttpResponse()->setCode(IResponse::S405_METHOD_NOT_ALLOWED);

    $this->sendJson([
        'status' => 'error',
        'code' => IResponse::S405_METHOD_NOT_ALLOWED,
        'message' => 'Wrong method please use ' . $method,
    ]);
}

Samozřejmě mám v Nette sandboxu upravený Error presenter tak, aby vracel Json s popisem chyby.

Otázka zní:
Když jsem udělal performance test pomocí aplikace ‚ReadyAPI‘ – 6000 requestů, tak jsem narazil na to, že moje řešení v Nette sandboxu má odezvu průměrně 62ms, zatímco Appite řešení má odezvu 220ms

Otestoval jsem si i Error 500 (N – 87ms, A – 202ms) a Error 404 (N – 81ms, A – 169ms).

Chci se zeptat, jestli mám někde chybu já, nebo jestli řešení čistě pro Api je prostě pomalejší, než obecné řešení pro web?

Editoval Polki (31. 8. 2021 21:32)

Felix
Nette Core | 1186
+
0
-

Ahoj. Mohl by jsi nasdilet zdrojaky? Osobne jsem pomalost Apitte nikde nezaznamenal.

Felix
Nette Core | 1186
+
0
-

Diky moc. Zkusil jsem Apache Benchmark a PHP development server. Vysledky jsou temer stejne. ± par ms vykyv, kdyz to poustim porad dokola.

Nette

➜ ab -n 100 -c 2 http://localhost:8002/api/v1/test
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
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).....done


Server Software:
Server Hostname:        localhost
Server Port:            8002

Document Path:          /api/v1/test
Document Length:        125 bytes

Concurrency Level:      2
Time taken for tests:   0.390 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      41000 bytes
HTML transferred:       12500 bytes
Requests per second:    256.48 [#/sec] (mean)
Time per request:       7.798 [ms] (mean)
Time per request:       3.899 [ms] (mean, across all concurrent requests)
Transfer rate:          102.69 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     4    7   0.8      7      10
Waiting:        4    7   0.8      7       9
Total:          4    8   0.8      7      10
WARNING: The median and mean for the total time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      8
  75%      8
  80%      8
  90%      9
  95%      9
  98%     10
  99%     10
 100%     10 (longest request)

Apitte

➜ ab -n 100 -c 2 http://localhost:8001/api/v1/chips/test
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
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).....done


Server Software:
Server Hostname:        localhost
Server Port:            8001

Document Path:          /api/v1/chips/test
Document Length:        123 bytes

Concurrency Level:      2
Time taken for tests:   0.363 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      27700 bytes
HTML transferred:       12300 bytes
Requests per second:    275.32 [#/sec] (mean)
Time per request:       7.264 [ms] (mean)
Time per request:       3.632 [ms] (mean, across all concurrent requests)
Transfer rate:          74.47 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     4    7   1.1      7      13
Waiting:        4    7   1.1      6      13
Total:          4    7   1.1      7      13

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      7
  75%      7
  80%      8
  90%      8
  95%     10
  98%     11
  99%     13
 100%     13 (longest request)
Polki
Člen | 553
+
0
-

Ok já to zkouším přímo na serveru, který je u stejného poskytovatele a s konfigurací jako produkce, kam se to bude nahrávat.

Od rána testuju a tohle jsou ± průměrné časy.

Nette sandbox: https://pasteboard.co/Kizjcng.png
Apitte: https://pasteboard.co/KiziU4b.png

Když to spustím lokálně tak je to cca 7–8ms vs 9–10ms, takže na locale to takový rozdíl není, ale straší mě ten server.

Min sloupec to na obrázku to nezobrazuje, ale vždy je to kolem 38ms u obou.. Bohužel nevím, jak si nechat zobrazit medián :D Je to prvně, co testuju API.

Polki
Člen | 553
+
0
-

Nette:

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 server.cz (be patient).....done


Server Software:        Apache/2.4.25
Server Hostname:        server.cz
Server Port:            80

Document Path:          /api/v1/chips/name
Document Length:        125 bytes

Concurrency Level:      2
Time taken for tests:   5.876 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      45700 bytes
HTML transferred:       12500 bytes
Requests per second:    17.02 [#/sec] (mean)
Time per request:       117.529 [ms] (mean)
Time per request:       58.764 [ms] (mean, across all concurrent requests)
Transfer rate:          7.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       39   51  14.1     49     119
Processing:    48   64  15.6     60     131
Waiting:       47   63  15.3     59     131
Total:         94  115  26.2    109     246

Percentage of the requests served within a certain time (ms)
  50%    109
  66%    114
  75%    118
  80%    120
  90%    130
  95%    179
  98%    237
  99%    246
 100%    246 (longest request)

U prvního pokusu na Apitte jsem myslel, že to spadlo, tak jsem to natvrdo ukončil a spustil znova. ‚Zaseklo‘ se to zase, tak jsem to nechal dojet, jestli se to neodsekne. Nebylo to zaseklý.. :D

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 server.cz (be patient).....done


Server Software:        Apache/2.4.25
Server Hostname:        server.cz
Server Port:            80

Document Path:          /api/v1/chips/name
Document Length:        123 bytes

Concurrency Level:      2
Time taken for tests:   258.980 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      28700 bytes
HTML transferred:       12300 bytes
Requests per second:    0.39 [#/sec] (mean)
Time per request:       5179.597 [ms] (mean)
Time per request:       2589.799 [ms] (mean, across all concurrent requests)
Transfer rate:          0.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       34   56  19.5     49     158
Processing:  5051 5122  91.4   5083    5478
Waiting:       45   64  19.0     57     159
Total:       5085 5178  94.4   5137    5538

Percentage of the requests served within a certain time (ms)
  50%   5137
  66%   5175
  75%   5191
  80%   5214
  90%   5326
  95%   5432
  98%   5475
  99%   5538
 100%   5538 (longest request)

Nechápu, co to způsobuje, ale znemožňuje mi to používat Apitte.

David Grudl
Nette Core | 8118
+
+2
-

Na tohle je nejlepší nainstalovat https://www.blackfire.io a zjistit, co přesně to brzdí, jinak je to hádání z křišťálové koule. Důvodů může být šíleně moc.

Polki
Člen | 553
+
0
-

David Grudl napsal(a):

Na tohle je nejlepší nainstalovat https://www.blackfire.io a zjistit, co přesně to brzdí, jinak je to hádání z křišťálové koule. Důvodů může být šíleně moc.

Okay, uvidíme, jestli s tím bude zákazník ok.