Skip to content

apt-get update/upgrade/install downloads packages at unacceptably slow speeds. #2477

Closed

Description

  • Your Windows build number: Microsoft Windows [Version 10.0.15063]

  • What you're doing and what's happening: sudo apt-get update && sudo apt-get upgrade -y downloads packages at less that 100 kB/s.
    image

  • What's wrong / what should be happening instead: apt should fetch packages much faster. My internet speed is 100 down / 10 up, on a bare-metal Linux installation or VirtualBox instance, apt is blazing fast. Packages are downloaded at upwards of 1024 kB/s.

  • Strace of the failing command, if applicable: n/a

Activity

  1. gravcat commented on Sep 8, 2017

    @gravcat

    If there is nothing meaningful in the environment and you don't mind completely destroying it, try the following in an elevated command prompt:

    lxrun /uninstall /full /y
    lxrun /install

    See if the problem persists if you completely redeploy the environment.

  2. sunilmut commented on Sep 8, 2017

    @sunilmut
    Member

    Audrey Drake (@RalphORama) - Thanks for your post. We are aware that WSL networking perf is not at par with native Linux, but should not be unbearable. There are plans to improve the WSL n/w perf. I am not sure if uninstall/reinstalling will change much here for you.

  3. gravcat commented on Sep 8, 2017

    @gravcat

    network speeds wget

    my network speeds are fine and maxing out my link speed on Microsoft Windows [Version 10.0.15063]

  4. therealkenc commented on Sep 8, 2017

    @therealkenc

    We are aware that WSL networking perf is not at par with native Linux

    Yeah WSL might not be on par with Real Linux, but we're talking Phoronix-style quibbling not mass degradation. I get awful apt-get speeds like the OP sometimes too (measured kbs/sec on a mbps link), but best evidence seems to be it is on Canonical's end (or something in between). I get the same thing in my Ubunutu VM from time to time. I am not sure why this is, but I think (speculating) that sometimes you just get a redirect to an unlucky server.

    Audrey Drake (@RalphORama)
    Best thing to do would be take Ubuntu out as a variable. Use speedtest from WSL CLI like poppoppop (@gravcat) suggests and then visit their website on Windows, and see if there is a serious gap in performance.

    $ sudo apt install speedtest-cli
    $ speedtest-cli
    Retrieving speedtest.net configuration...
    Retrieving speedtest.net server list...
    Testing from Skyway West (69.50.175.134)...
    Selecting best server based on latency...
    Hosted by Shaw Communications (Vancouver, BC) [28.08 km]: 28.778 ms
    Testing download speed........................................
    Download: 34.39 Mbit/s
    Testing upload speed..................................................
    Upload: 5.22 Mbit/s
    

    If you see an orders-of-magnitude difference between Windows and WSL, report back because that would be good to know; it is always possible there is something unique going on with your setup.

  5. Aerocatia commented on Sep 9, 2017

    @Aerocatia

    I found that Windows Defender absolutely murders performance in WSL, especially tools like apt-get.
    Try temporally disabling it and see if that improves it or not.

  6. heldchen commented on Sep 9, 2017

    @heldchen

    I found that Windows Defender absolutely murders performance in WSL, especially tools like apt-get.
    Try temporally disabling it and see if that improves it or not.

    this. Windows Defender really messes with I/O actions in WSL, not just with apt-get... adding scan exemptions does not seem to help much.

  7. therealkenc commented on Sep 9, 2017

    @therealkenc

    this. Windows Defender really messes with I/O actions in WSL

    It does. But keep in mind, in the OP this was the 'Get' phase, which is literally just a curl of a .deb. 46.6 kilobytes per second on a 100Mbit/s downlink. Install phase I understand, sure. Windows Defender gets upset when thousands of little untrusted files start appearing from nowhere (from Defender's perspective) though its filesystem filter driver. But if it were Defender you should see the same slowdown on a bog standard curl from a fast server, and you don't; at least not to this degree. Couple that with the fact that turning Defender off doesn't help. So, something else. I could be wrong, because Defender is a ginormous black box that does who knows what, on or off. But I'm not seeing the causality here.

  8. RalphORama commented on Sep 9, 2017

    @RalphORama
    Author

    I reinstalled WSL as poppoppop (@gravcat) suggested, and installed speedtest-cli. After running speedtest-cli and visiting the speedtest website, it appears WSL only uses 5% of my available bandwidth, maximum (1.6 Mbit/s vs 36 Mbit/s). I believe I have Windows Defender disabled, and I don't think I have any other programs that interfere with I/O on my machine. I use Malwarebytes as my antivirus, which doesn't run in the background. I'll try creating a firewall rule for bash.exe and report back.

    Update: Creating a firewall rule and switching to OpenDNS had no effect on apt's download speeds.

    image
    image

  9. benhillis commented on Oct 5, 2017

    @benhillis
    Member

    therealkenc - Thanks for the repro steps. I tracked this down to a directory rename failing due something that has a handle open to one of the directory's children. Unfortunately this is an NTFS limitation that I can't think of a workaround without NTFS supporting posix-style rename. I know they were looking at that at some point, but I'm not sure of the status.

  10. deleted a comment from therealkenc on Oct 10, 2017
  11. DarkIlluminatus commented on Jan 27, 2018

    @DarkIlluminatus

    I am also experiencing this issue, did the solution suggested by poppoppop (@gravcat) work for anyone?
    I would hate to have to download the entire distro again at these below 100 kB/s speeds, so am reticent about attempting it.

  12. leandrocrs commented on Jan 27, 2018

    @leandrocrs

    Just turn off Windows Defender Real-time protection.

    Add WSL folder and apt process in exclusion list will not work.

    You should to completely disable real-time protection, reboot and will see how fast it will be

  13. DarkIlluminatus commented on Jan 28, 2018

    @DarkIlluminatus
  14. Garry050 commented on Feb 22, 2018

    @Garry050

    same here.
    speedtest: both good speed (download: 70-90Mbps)
    apt: always 30-300kb/s (ftp.jaist.ac.jp)

    Using ESET Internet Security 11. no help disable anti-virus.
    16299.214

  15. 66 remaining items

  16. danieliser commented on Jan 31, 2021

    @danieliser

    Aymane Boumaaza (@Aymane11) I actually have a PowerShell script I use to do this automatically for all WSL instances. You will need an escalated PowerShell instance (Run as Admin).

    ############
    # This script will add your WSL environments to the Windows Defender exclusion list so that
    # realtime protection does not have an adverse effect on performance.
    #
    # You should be aware that this could make your system less secure. Use at your own risk.
    # Note: This should be run from an administrative PowerShell prompt
    ############
    
    # Find registered WSL environments
    $wslPaths = (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | ForEach-Object { Get-ItemProperty $_.PSPath}).BasePath
    
    # Get the current Windows Defender exclusion paths
    $currentExclusions = $(Get-MpPreference).ExclusionPath
    if (!$currentExclusions) {
      $currentExclusions = ''
    }
    
    # Find the WSL paths that are not excluded
    $exclusionsToAdd = ((Compare-Object $wslPaths $currentExclusions) | Where-Object SideIndicator -eq "<=").InputObject
    
    # List of paths inside the Linux distro to exclude (https://github.com/Microsoft/WSL/issues/1932#issuecomment-407855346)
    $dirs = @("\bin", "\sbin", "\usr\bin", "\usr\sbin", "\usr\local\bin", "\usr\local\go\bin")
    
    # Add the missing entries to Windows Defender
    if ($exclusionsToAdd.Length -gt 0) {
      $exclusionsToAdd | ForEach-Object { 
        
        # Exclude paths from the root of the WSL install
        Add-MpPreference -ExclusionPath $_
        Write-Output "Added exclusion for $_"
    
        # Exclude processes contained inside WSL
        $rootfs = $_ + "\rootfs"
        $dirs | ForEach-Object {
            $exclusion = $rootfs + $_ + "\*"
            Add-MpPreference -ExclusionProcess $exclusion
            Write-Output "Added exclusion for $exclusion"
        }
      }
    }
    
  17. danieliser commented on Jan 31, 2021

    @danieliser

    Hope this part helps everyone, though I had the above for I/O performance improvements, it had no impact on connection speeds.

    However what I did find, and my tests are below, is that disabling Windows Defender Firewall (Internet rules) does resolve it for the speed test, fixes downloading files directly as well.

    BUT I'm still not getting good speed in docker containers running tensorflow projects in Jupyter notebooks. 24M files are taking minutes, where they take seconds if I try them via WSL terminal directly or on Windows

    I should clarify this is using Docker CLI as NVidia CUDA support on WSL as you know isn't supported via Docker Desktop containers. So I'm not sure how or if that plays into it.

    Baseline: Speedtest from Windows)
    image

    WSL Before & After disabling Firewall
    image

    Next I need to figure out what needs to be unblocked to ensure this doesn't happen without leaving firewall off entirely.

    Any thoughts on specifically what to unblock? Can't imagine port based rules will do. Not sure which application you could select to unblock either.

  18. danieliser commented on Jan 31, 2021

    @danieliser

    I have narrowed the docker issue as well now. Seems to be a bottleneck due to using a WiFi connection.

    Switching to a wired connection and WSL2 -> Docker CE containers for tensorflow with GPU support will now download using the entire connection.

    No idea why that is. Haven't been able to find any info on why docker has issues with wifi.

  19. SanderElias commented on Jun 18, 2021

    @SanderElias

    I'm wired to a 600Mb connection. This is the only thing that is slow:
    image

    I already switched connections, removed code-insiders completely, and reinstalled them.
    The first reinstallation goes quick then, but with every upgrade I'm back to slowness?

  20. Arian8j2 commented on Aug 20, 2021

    @Arian8j2

    Sven Groot (@SvenGroot) Solution works for me, Also remember to change security mirrors too, So completed command will be like:
    mirror="us.archive.ubuntu.com" && sudo sed -i "s/archive.ubuntu.com/$mirror/; s/security.ubuntu.com/$mirror/" /etc/apt/sources.list, Also not sure that is it good idea to change security mirrors or not.

  21. sbin-github commented on Oct 12, 2021

    @sbin-github

    image
    I just installed WSL2 on my desktop.
    I've completely turned off the windows defender and real-time protection, and tried several mirror servers in my country.
    However, it never goes over 50kB/s.
    What is the problem, seriously?

  22. j0e1an commented on Oct 18, 2021

    @j0e1an

    I fixed it by running this to PowerShell Admin:

    New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

    This basically opens the interface for WSL per this issue comment: #4585#issuecomment-610061194_

    No turning off of windows defender necessary.

    Work like a charm. Hate firewall just doing this.

  23. emadha commented on Feb 20, 2022

    @emadha

    i copied the /etc/resolve.conf from ubuntu to kali's resolv.conf and it solved the problem

    # [network]
    # generateResolvConf = false
    nameserver 192.x.x.184
    nameserver xxxx:0:0:ffff::1
    nameserver xxxx:0:0:ffff::2
    

    this solved my kali issue, I had to wsl --showdown from powershell and restart kali for this to work.


    now I dunno how the ubuntu got generated, ubuntu was doing the same issue as kali, probably wsl --shutdown solved it?
    anyway, that's the only change I did to my wsl, oh and I moved to WSL 1 as well

    ## Update
    Apparently it's windows defender related issue, after putting it back on and restarting wsl downloads became very slow, so I had to deactivate realtime protection then wsl --shutdown for it to work.

  24. jhagege commented on Feb 25, 2023

    @jhagege

    I realized the issue for me was that antivirus ESET was blocking the traffic for WSL Ubuntu.
    Unblocked by going to Setup --> Network --> Troubleshooting Wizard --> Unblock.

  25. craigloewen-msft commented on Sep 19, 2023

    @craigloewen-msft
    Member

    Hi folks, we have put out a new update that aims to address networking issues in WSL. In your .wslconfig file you can set experimental.networkingMode=mirrored, as well as some other key settings that should improve your network compatibility! Please try them out and let us know what you think.

    More info on this release and the changes can be found here in the blog post.

    Please note: You need to be on a Windows Insiders version to use the new networking settings (Any channel of Windows Insiders will do, including release preview). If you see the "These are not supported" messages it means that your current Windows version doesn't have support, and you will need to upgrade. These features will eventually be coming to Windows 11 22H2.

  26. meydiwahendra commented on Sep 24, 2023

    @meydiwahendra

    until now 2023, its still happening, this is servers relative issues !!

    if you're an Asian, its easy to fix that problem, just copy and paste

    sudo sed -i "s/archive.ubuntu.com/sg.archive.ubuntu.com/" /etc/apt/sources.list &&
    sudo apt update

    see the different

    Screenshot (2)

    mine running on 30mbps speed

  27. DrorDvash commented on Jan 1, 2024

    @DrorDvash

    I realized the issue for me was that antivirus ESET was blocking the traffic for WSL Ubuntu. Unblocked by going to Setup --> Network --> Troubleshooting Wizard --> Unblock.

    Thanks! helped me too with ESET Internet Security

  28. OneBlue commented on May 14, 2024

    @OneBlue
    Collaborator

    Hi ! Please try the latest networking features that we've added in WSL. Those should greatly improve performance.

    If the issue still remains, please reopen this issue.

  29. bukowa commented on Jun 26, 2024

    @bukowa

    Changing nameservers

    Hi ! Please try the latest networking features that we've added in WSL. Those should greatly improve performance.

    If the issue still remains, please reopen this issue.

    Doesn't work for me.
    The only thing that works is to change dns in /etc/resolv.conf
    But wsl will automatically change them after restart so...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions