2017-12-02 183 views
0

我正在使用docker撰寫本地開發環境在macOS上撰寫。我們有多個用php編寫的應用程序,並且可以與Symfony一起運行。代碼通過卷附加到容器上。與Linux主機相比,我遇到了非常差的性能問題。泊塢窗 - 緩存掛載音量同步延遲

事實證明,問題是由基於osxfs(一種共享文件系統解決方案,專門用於Mac的Docker)的掛載卷導致的。

問題是很好的解釋在這裏:https://blog.docker.com/2017/05/user-guided-caching-in-docker-for-mac/

性能大大提高,引進安裝卷的緩存模式後。但是,它允許在主機上的更新出現在容器中之前出現一些延遲。文件沒有具體說明這個延遲。你知道主機上的代碼和容器內部的代碼之間的同步有多快?

volumes: 
    - ./php_code:/var/www:cached 

回答

0
  1. 使用NFS(不與高塞拉利昂工作 - more details here

泊塢窗機,NFS $ {} DOCKER_MACHINE_NAME --mount-OPTS = 「noacl,async,nolock,vers = 3,udp,noatime,actimeo = 1」

  1. 讓您PHP緩存容器內 - 例如在/tmp/app_cache/* - 或者內存/dev/shm/app_cache/*(不推薦)

要保持容器改變內部緩存中的AppKernel.php(用於Symfony的4.0 Kernel.php

...  
public function getCacheDir() 
{ 
    if ($this->environment === 'env') { 
     // Store in RAM. 
     // return '/dev/shm/symfony_docker_test/cache/'.$this->environment; 

     // Store in docker container (not docker-machine unless docker-compose volume is mounted). 
     return '/tmp/symfony_cache/cache/' . $this->environment; 
    } 

    return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); 
} 
... 

結果與解決方案提到:cached

Time taken for tests: 20.396 seconds 
Complete requests:  100 
Failed requests:  0 
Total transferred:  82700 bytes 
HTML transferred:  31900 bytes 
Requests per second: 4.90 [#/sec] (mean) 
Time per request:  203.963 [ms] (mean) 
Time per request:  203.963 [ms] (mean, across all concurrent requests) 
Transfer rate:   3.96 [Kbytes/sec] received 

結果與解決方案提到而不:cached

Time taken for tests: 18.911 seconds 
Complete requests:  100 
Failed requests:  0 
Total transferred:  82700 bytes 
HTML transferred:  31900 bytes 
Requests per second: 5.29 [#/sec] (mean) 
Time per request:  189.111 [ms] (mean) 
Time per request:  189.111 [ms] (mean, across all concurrent requests) 
Transfer rate:   4.27 [Kbytes/sec] received 
+0

選項2是優選的。關於Docker的全部觀點是在版本化的映像中包含組成應用程序的所有內容。 –

+0

感謝這個,結果非常有趣。你認爲它是用溫暖的:緩存來衡量的嗎?我將檢查我們是否可以將緩存文件夾移動到容器中。另外NFS可能會有所幫助。另一種選擇是docker-sync http://docker-sync.io/但是,問題是:使用緩存模式進行卷裝入時,容器中的更新出現在容器中之前的延遲是多少。 – Ludek

+0

@Ludek繼續玩其他解決方案。儘管我知道任何能夠顯着提高速度而沒有缺點。你注意到'':chached'會導致同步延遲。我會堅持以上這些,因爲它們不會導致任何重大問題。速度的提高對開發環境來說是非常重要的。乾杯。 –