0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

docker バインドマウントをreadonlyにすれば早くなるか?

Posted at

macでdocker開発時にファイルio?周りで遅くなる問題があるが、バインドマウントをreadonlyにすれば早くなるのか調べる。
なんとなくreadonlyにした方が早くなる気がする

コンテナの/appにLaravleのコードをマウントする。

FROM centos:centos8

RUN dnf module install -y php:7.4

WORKDIR /app
CMD [ "php", "artisan", "serve", "--port=80", "--host=0.0.0.0" ]

まずは普通にroオプション付けずにマウントする。

$ docker run -it --rm -v ~/Documents/test/docker/volume_test/ro_test:/app -p 8080:80 ro_test

負荷テストにはabテストを使用。
10人で10リクエスト = 合計100リクエストで試験。
1秒あたり2.78リクエスト捌ける
全部処理するのに36秒

$ ab -n 100 -c 10 http://localhost:8080/
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).....done


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        17473 bytes

Concurrency Level:      10
Time taken for tests:   35.945 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      1861900 bytes
HTML transferred:       1747300 bytes
Requests per second:    2.78 [#/sec] (mean)
Time per request:       3594.549 [ms] (mean)
Time per request:       359.455 [ms] (mean, across all concurrent requests)
Transfer rate:          50.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:   380 3392 655.6   3578    3659
Waiting:      379 3391 655.7   3578    3659
Total:        380 3392 655.6   3578    3659

Percentage of the requests served within a certain time (ms)
  50%   3578
  66%   3596
  75%   3609
  80%   3616
  90%   3630
  95%   3642
  98%   3653
  99%   3659
 100%   3659 (longest request)

readonlyありの方でマウントする

$ docker run -it --rm -v ~/Documents/test/docker/volume_test/ro_test:/app:ro -p 8080:80 ro_test

1秒あたり2.27リクエスト捌ける
全部処理するのに43秒
あれ、readonlyの方が処理が遅くなっている。

ab -n 100 -c 10 http://localhost:8080/
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).....done


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        519560 bytes

Concurrency Level:      10
Time taken for tests:   43.979 seconds
Complete requests:      100
Failed requests:        0
Non-2xx responses:      100
Total transferred:      51981200 bytes
HTML transferred:       51956000 bytes
Requests per second:    2.27 [#/sec] (mean)
Time per request:       4397.921 [ms] (mean)
Time per request:       439.792 [ms] (mean, across all concurrent requests)
Transfer rate:          1154.25 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:   455 4155 808.2   4374    4487
Waiting:      447 4145 808.2   4362    4478
Total:        455 4155 808.2   4374    4488

Percentage of the requests served within a certain time (ms)
  50%   4374
  66%   4400
  75%   4436
  80%   4444
  90%   4457
  95%   4471
  98%   4483
  99%   4488
 100%   4488 (longest request)

readonlyの時はstorage以下に書き込もうとしてエラーになって余計に時間がかかっている・・・?
試しにstorage以下だけroを外してみる。

マウント時に後から-vを追加することで上書きできるらしい。

$ docker run -it --rm -v $(pwd)/ro_test:/app:ro -v $(pwd)/ro_test/storage:/app/storage -p 8080:80 ro_test

abテストすると、
1秒あたり2.73リクエスト捌ける
全部処理するのに36秒
と、ほぼroなしの状態と同じになった。

ab -n 100 -c 10 http://localhost:8080/
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).....done


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        17473 bytes

Concurrency Level:      10
Time taken for tests:   36.620 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      1861900 bytes
HTML transferred:       1747300 bytes
Requests per second:    2.73 [#/sec] (mean)
Time per request:       3661.974 [ms] (mean)
Time per request:       366.197 [ms] (mean, across all concurrent requests)
Transfer rate:          49.65 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   370 3461 688.7   3613    4053
Waiting:      369 3461 688.8   3613    4053
Total:        370 3461 688.7   3613    4054

Percentage of the requests served within a certain time (ms)
  50%   3613
  66%   3629
  75%   3640
  80%   3644
  90%   4031
  95%   4044
  98%   4050
  99%   4054
 100%   4054 (longest request)

このことからro付けても早くなるわけではなさそう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?