Mac OSX上非常慢的laravel homestead/vagrant/virtualbox [英] Very slow laravel homestead/vagrant/virtualbox on Mac OSX

查看:82
本文介绍了Mac OSX上非常慢的laravel homestead/vagrant/virtualbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上使用 Homestead + Vagrant + Virtualbox .

问题

虽然我发现了很多解决慢响应时间(例如TTFB)的方法/答案,但它们都不起作用.我的响应时间在25到32秒之间变化,这对于本地开发来说显然是不可接受的.

建议的解决方案

我从此处尝试了许多建议的解决方案: https://github.com/laravel/homestead/issues/901

并且还阅读并尝试了以下这些线程的许多建议:

即使有已接受的答案,也没有一个能帮助我.

禁用xdebug

我可以这么说禁用xdebug 就像解释的此处一样,帮助我保存了5秒.

更改光盘大小

按照建议在此处将VM的磁盘大小从动态更改为固定>,并在此处进行了解释,根本没有帮助(结果甚至更糟).

根据建议使用NFS(同步文件夹)

也尝试过(homestead.yaml)

 文件夹:--地图:"/Users/myuser/PhpstormProjects/example.com"到:/home/vagrant/code类型:"nfs"选项:mount_options:['nolock','vers = 3','udp','noatime','actimeo = 1'] 

在这两种情况下NFS都可以正常工作,但是它并没有改变有关页面加载时TTFB的情况.

设置natdnshostresolver:关闭

我还尝试按照建议此处关闭natdnshostresolver它并没有改变任何事情.

调整Virtualbox图像

当然,我也尝试增加RAM,CPU,图形等内容,但是如您所见,这无济于事.

还有其他建议

截至目前,我也愿意尝试代客服务或其他您可以提供的建议/解决方案.

非常感谢!

更新1

在我的VM上更改 nginx.conf (在@emotality建议进行调整之后)确实有所帮助.为了完整性和可能性,可能还要进行更多调整,这是nginx.conf文件的整个http部分.

  http {### 基本设置##发送文件;tcp_nopush on;tcp_nodelay;#keepalive_timeout 65;types_hash_max_size 2048;#server_tokens关闭;keepalive_disable无;keepalive_requests 200;keepalive_timeout 300秒;server_names_hash_bucket_size 64;#server_name_in_redirect关闭;包括/etc/nginx/mime.types;default_type应用程序/八位字节流;###SSL设置##ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#删除SSLv3,参考:POODLEssl_prefer_server_ciphers;###记录设置##access_log/var/log/nginx/access.log;error_log/var/log/nginx/error.log;###Gzip设置##gzip on;#gzip_vary on;#gzip_proxied any;#gzip_comp_level 6;#gzip_buffers 16 8k;#gzip_http_version 1.1;#gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml + rss text/javascript;###虚拟主机配置##包括/etc/nginx/conf.d/*.conf;包括/etc/nginx/sites-enabled/*;} 

更新2

homestead.yaml的内容:

  ip:192.168.10.14内存:4096中央处理器:2提供者:virtualboxnatdnshostresolver:关闭授权:〜/.ssh/id_rsa.pub按键:-〜/.ssh/id_rsa资料夹:--地图:"/Users/myUser/PhpstormProjects/exampleproject.com"到:/home/vagrant/code类型:"nfs"选项:mount_options:['nolock','vers = 3','udp','noatime','actimeo = 1']网站:--地图:exampleproject.local到:/home/vagrant/code数据库:-宅基地特征:--mariadb:错误--ohmyzsh:错误--网络驱动程序:错误名称:exampleproject主机名:exampleproject 

Vagrantfile的内容:

 #-*-模式:ruby-*-#vi:设置ft = ruby​​:需要'json'需要'yaml'VAGRANTFILE_API_VERSION || ="2"confDir = $ confDir || = File.expand_path("vendor/laravel/homestead",File.dirname(__ FILE__))homesteadYamlPath = File.expand_path("Homestead.yaml",File.dirname(__ FILE__))homesteadJsonPath = File.expand_path("Homestead.json",File.dirname(__ FILE__))afterScriptPath ="after.sh"configurationScriptPath ="user-customizations.sh"aliasesPath =别名"需要File.expand_path(confDir +'/scripts/homestead.rb')Vagrant.require_version'> = 2.2.4'Vagrant.configure(VAGRANTFILE_API_VERSION)做| config |如果File.exist?aliasPath然后config.vm.provision文件",源:aliassPath,目标:"/tmp/bash_aliases"config.vm.provision"shell"做| s |s.inline ="awk'{sub(\" \ r $ \,\" \);打印}'/tmp/bash_aliases>/home/vagrant/.bash_aliases"结尾结尾如果File.exist?homesteadYamlPath然后设置= YAML :: load(File.read(homesteadYamlPath))elsif File.exist?homesteadJsonPath然后设置= JSON :: parse(File.read(homesteadJsonPath))别的中止在+ File.dirname(__ FILE__)中找不到宅基地设置文件"结尾Homestead.configure(配置,设置)如果File.exist?afterScriptPath然后config.vm.provision"shell",路径:afterScriptPath,特权:false,keep_color:true结尾如果File.exist?然后使用customizationScriptPathconfig.vm.provision"shell",路径:customizationScriptPath,特权:false,keep_color:true结尾如果Vagrant.has_plugin?('vagrant-hostsupdater')config.hostsupdater.aliases = settings ['sites'].map {| site |site ['map']}elsif Vagrant.has_plugin?('vagrant-hostmanager')config.hostmanager.enabled = trueconfig.hostmanager.manage_host = trueconfig.hostmanager.aliases = settings ['sites'].map {| site |site ['map']}结尾结尾 

解决方案

谢谢大家,但是我发现了一个非常有趣的解决方案,或者说是我遇到的一个问题.

我正在使用本地环境进行wordpress安装.在使用Memcached的wp-content文件夹中有一个名为" object-cache.php "的文件.Memcached已安装在宅基地内,但配置与实时服务器不同.

这导致本地文件无法正确缓存,最终导致代码为每个请求从数据库中提取所有可用选项.

因此,总而言之,这是一个巨大的缓存问题.

删除object-cache.php文件现在是我的解决方案(导致TTFB为1.23秒).

如果有人遇到类似问题,我就把它留在这里.再次感谢您提供的所有帮助,并以为你们对此表示感谢.

I am using Homestead + Vagrant + Virtualbox on a Mac.

Problem

While I found lots of threads/answers how to fix slow response times (e.g. TTFB) none of them worked. My response times vary between 25 - 32 seconds, which of obviously is not acceptable for local development.

Suggested Solutions

I have tried a lot of suggested solutions from here: https://github.com/laravel/homestead/issues/901

And have also read and tried many suggestions from these threads:

Even though there were accepted answers, none of them helped me.

Disabling xdebug

I can say that Disabling xdebug like explained here helped me to save 5 seconds.

Changing disc size

While changing the VM's disc size from dynamic to fixed as suggested here and explained here didn't help at all (result was even worse).

Using NFS (sync folders) as suggested here

Also setting homestead/vagrant to NFS didn't help a thing.

Tried (vagrant file):

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", type: "nfs", mount_options:['nolock,vers=3,udp,noatime,actimeo=1']
end

Also tried (homestead.yaml)

folders:
    -
        map: '/Users/myuser/PhpstormProjects/example.com'
        to: /home/vagrant/code
        type: "nfs"
        options:
            mount_options: ['nolock','vers=3','udp','noatime','actimeo=1']

NFS was working in both cases but it didn't change a thing regarding TTFB on page load.

Setting natdnshostresolver: off

I also tried to turn off natdnshostresolver as suggested here It didn't change a thing.

Adjusting Virtualbox Image

Of course I also tried to increase RAM, CPUs, Graphic stuff, etc. but as you can figure it didn't help.

Any other suggestions

As of now I'm also open to try e.g. valet or for any other recommendations / solutions you could give.

Thanks a lot in advance!

Update 1

Altering the nginx.conf on my VM (after @emotality suggested a tweak) did help a little bit. For the sake of completeness and the possibility there could be tweaked even a little bit more, here's the whole http part of the nginx.conf file.

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        # keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        keepalive_disable none;
        keepalive_requests 200;
        keepalive_timeout 300s;

        server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


Update 2

Content of homestead.yaml:

ip: 192.168.10.14
memory: 4096
cpus: 2
provider: virtualbox
natdnshostresolver: off
authorize: ~/.ssh/id_rsa.pub
keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: '/Users/myUser/PhpstormProjects/exampleproject.com'
        to: /home/vagrant/code
        type: "nfs"
        options:
            mount_options: ['nolock','vers=3','udp','noatime','actimeo=1']
sites:
    -
        map: exampleproject.local
        to: /home/vagrant/code
databases:
    - homestead
features:
    -
        mariadb: false
    -
        ohmyzsh: false
    -
        webdriver: false
name: exampleproject
hostname: exampleproject

Content of Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path("vendor/laravel/homestead", File.dirname(__FILE__))

homesteadYamlPath = File.expand_path("Homestead.yaml", File.dirname(__FILE__))
homesteadJsonPath = File.expand_path("Homestead.json", File.dirname(__FILE__))
afterScriptPath = "after.sh"
customizationScriptPath = "user-customizations.sh"
aliasesPath = "aliases"

require File.expand_path(confDir + '/scripts/homestead.rb')

Vagrant.require_version '>= 2.2.4'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    if File.exist? aliasesPath then
        config.vm.provision "file", source: aliasesPath, destination: "/tmp/bash_aliases"
        config.vm.provision "shell" do |s|
            s.inline = "awk '{ sub(\"\r$\", \"\"); print }' /tmp/bash_aliases > /home/vagrant/.bash_aliases"
        end
    end

    if File.exist? homesteadYamlPath then
        settings = YAML::load(File.read(homesteadYamlPath))
    elsif File.exist? homesteadJsonPath then
        settings = JSON::parse(File.read(homesteadJsonPath))
    else
        abort "Homestead settings file not found in " + File.dirname(__FILE__)
    end

    Homestead.configure(config, settings)

    if File.exist? afterScriptPath then
        config.vm.provision "shell", path: afterScriptPath, privileged: false, keep_color: true
    end

    if File.exist? customizationScriptPath then
        config.vm.provision "shell", path: customizationScriptPath, privileged: false, keep_color: true
    end

    if Vagrant.has_plugin?('vagrant-hostsupdater')
        config.hostsupdater.aliases = settings['sites'].map { |site| site['map'] }
    elsif Vagrant.has_plugin?('vagrant-hostmanager')
        config.hostmanager.enabled = true
        config.hostmanager.manage_host = true
        config.hostmanager.aliases = settings['sites'].map { |site| site['map'] }
    end
end

解决方案

Thanks to all of you guys, but I found a quite interesting solution or rather an issue that I had.

I was using the local environment for a wordpress install. There was a file called "object-cache.php" in the wp-content folder which uses Memcached. Memcached is installed within homestead but seems to have a different configuration than my live server.

This leads to local files not being cached properly, which ultimately results in the code pulling all available options from the database for each request.

So in sum it was a huge caching issue.

Removing the object-cache.php file is now my solution (resulting in a TTFB of 1.23 seconds).

I just leave this here in case anyone runs into a similar issue. Thanks again for all the help and thought you guys put into this.

这篇关于Mac OSX上非常慢的laravel homestead/vagrant/virtualbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆