Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RalphORama opened this issue Sep 8, 2017 · 91 comments
Labels

Comments

@RalphORama
Copy link

  • 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

@gravcat
Copy link

gravcat commented Sep 8, 2017

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.

@sunilmut
Copy link
Member

sunilmut commented Sep 8, 2017

@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.

@gravcat
Copy link

gravcat commented Sep 8, 2017

network speeds wget

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

@therealkenc
Copy link
Collaborator

therealkenc commented Sep 8, 2017

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.

@RalphORama
Best thing to do would be take Ubuntu out as a variable. Use speedtest from WSL CLI like @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.

@Aerocatia
Copy link

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.

@heldchen
Copy link

heldchen commented Sep 9, 2017

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.

@therealkenc
Copy link
Collaborator

therealkenc commented Sep 9, 2017

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.

@RalphORama
Copy link
Author

RalphORama commented Sep 9, 2017

I reinstalled WSL as @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

@ghost
Copy link

ghost commented Sep 17, 2017

image

image

@benhillis
Copy link
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.

@DarkIlluminatus
Copy link

DarkIlluminatus commented Jan 27, 2018

I am also experiencing this issue, did the solution suggested by @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.

@leandrocrs
Copy link

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

@DarkIlluminatus
Copy link

DarkIlluminatus commented Jan 28, 2018 via email

@Garry050
Copy link

Garry050 commented Feb 22, 2018

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

@benhillis
Copy link
Member

@DarthSpock - unfortunately I think the posix-style rename work the ntfs team did doesn't handle the case where a directory has children with open handles. Adding @SvenGroot to confirm.

@therealkenc
Copy link
Collaborator

@benhillis
Your "this is an NTFS limitation that I can't think of a workaround" comment was posted to the wrong thread at the time (you thank me for repro steps that don't exist here). That is #640 aka #1529, which is unrelated to "apt-get update/upgrade/install downloads packages at unacceptably slow speeds".

Adding SvenGroot to confirm.

Like this

@sewashinobi
Copy link

I can confirm, this is slow as hell. For me the speed is 219 B/s, while my internet speed on windows is 24mbps

@mskd12
Copy link

mskd12 commented Mar 3, 2018

I can confirm as well, the speed has dropped down significantly especially when downloading many things

@Wingmore
Copy link

Wingmore commented Mar 7, 2018

Has anyone found a fix? getting speeds of 40 kB/s

@rondi74
Copy link

rondi74 commented Mar 7, 2018

I'm having the same problem! >_<

@SvenGroot
Copy link
Member

SvenGroot commented Mar 7, 2018

Ubuntu on WSL uses the Ubuntu's main archive mirror, which may not be the fastest option depending on your location. Could those who are having this issue try choosing a local mirror from https://launchpad.net/ubuntu/+archivemirrors (tip: most countries have a mirror like us.archive.ubuntu.com, so you can try that for your country before scouring the list), updating /etc/apt/sources.list to use that mirror instead of archive.ubuntu.com, and see if that improves your download speed?

Make sure you run sudo apt update after editing sources.list.

You can use sed to make the change. For example, to change from archive.ubuntu.com to us.archive.ubuntu.com:
sudo sed -i "s/archive.ubuntu.com/us.archive.ubuntu.com/" /etc/apt/sources.list

@WSLUser
Copy link

WSLUser commented Mar 7, 2018

Running Synaptic on Kali goes rather fast. Faster than normal apt surprisingly. But even apt on Kali runs faster than Ubuntu. Which seems to point to agreement with what's said above.

@therealkenc
Copy link
Collaborator

You can confirm whether the variable is your Ubuntu mirror by testing against speedtest.net from within WSL with speedtest-cli.

sudo apt install python-pip
pip install speedtest-cli   # installs in ~/.local/bin which is in your default path
speedtest-cli

@brunoeustaquio
Copy link

@SvenGroot tks man, it´s way better now

@doomsbuster
Copy link

Turning off Windows Defender Realtime protection did the trick. All other options did not work.

@navneethc
Copy link

I'm having the same problems as well. Installed WSL only a month or so ago, and any time I try to install/update using apt-get I first get abysmal speeds (100s of Bps to KBps on a 75 Mbps connection) and then everything comes to a screeching halt, at which point I kill it.

Windows 10.0.16299 (and Defender is turned off).

@noodlehaus
Copy link

noodlehaus commented Jun 10, 2020

Following THIS LINK, I created an exception on Windows Defender and it worked like a charm(!!!).

TL;DR

  1. Get the UbuntuOnLinux (or your distro of choice) installation path: %USERPROFILE%\AppData\Local\Packages and lookup for something like CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc. Copy the path of that folder.
  2. Open up your Windows Defender & add an exception of that folder. Follow:
    Settings > Update & Security > Windows Defender > Open Windows Defender Secutiry Central > Protection Against Viruses & Threats > Advanced Config… > Exclusions > Add or Remove > Add > Folder and then select the folder. Or you can also paste that folder's path.

You should also check that article as it has other methods as well.

Tried this comment by @aqeebimtiaz a few days back, and this has certainly made things significantly better, though still not as fast as if i was outside WSL. But for code editing, the speed performance makes no difference, only when needing to download huge files.

@BeaudanBrown
Copy link

Haven't read all the responses to see how many people have tried this but the mirrors generated from this tool fixed the issue for me

@idamachmadfaizin
Copy link

idamachmadfaizin commented Jun 23, 2020

Just turn off windows defender real-time protection.
or
Add WSL folder in windows defender exclusion list.
i'm using Ubuntu 20.04. and path is "C:\Users%username%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc"

It's work for me.

@anvillasoto
Copy link

anvillasoto commented Aug 14, 2020

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.

@pcgeek86
Copy link

@anvillasoto Wow, thank you! That actually works for me! I just tested it on an outdated instance of WSL. It's downloading packages at full speed now. 👍🏻

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

@NoelJacob
Copy link

Building on what Sven said, here is a quick and easy command to change apt to automatically point to a mirror inside your country. sed -i -e 's/http:\/\/archive/mirror:\/\/mirrors/' -e 's/\/ubuntu\//\/mirrors.txt/' /etc/apt/sources.list

#2477 (comment) by @Austin76016 worked, I guess.

Can anyone tell me this equalent for Kali-Linux? or how does this work?

@giosal
Copy link

giosal commented Nov 9, 2020

Same issue here - all network related operations running very slowly on WSL 2 Ubuntu 20.04 running on Windows 10 x64 Insider Build 20241.
image
Whereas from Chrome on Windows:
image
And another computer it's working perfectly (Windows 10 20H2):
image

I mean, seriosuly? 0.01 Mbps?..

@waqasaliBSSe-F17-58
Copy link

here is website you can use find internnet speed https://www.internetmeter.net/,if you want to find your ping them go to this link
https://www.internetmeter.net/ping.html if you want to find your jitter speed then simple click on this link https://www.internetmeter.net/jitter.html
best internet speed finder website https://www.internetmeter.net/

1 similar comment
@waqasaliBSSe-F17-58
Copy link

here is website you can use find internnet speed https://www.internetmeter.net/,if you want to find your ping them go to this link
https://www.internetmeter.net/ping.html if you want to find your jitter speed then simple click on this link https://www.internetmeter.net/jitter.html
best internet speed finder website https://www.internetmeter.net/

@chuanqisun
Copy link

chuanqisun commented Nov 24, 2020

Same issue. WSL 2, Ubuntu 20.04 LTS on Windows 10 Pro 19041.630

It's definitely not caused by a slow mirror.

image

@Aymane11
Copy link

Aymane11 commented Dec 3, 2020

Following THIS LINK, I created an exception on Windows Defender and it worked like a charm(!!!).

TL;DR

1. Get the UbuntuOnLinux (or your distro of choice) installation path: `%USERPROFILE%\AppData\Local\Packages` and lookup for something like **CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc**. Copy the path of that folder.

2. Open up your Windows Defender & add an exception of that folder. Follow:
   `Settings > Update & Security > Windows Defender > Open Windows Defender Secutiry Central > Protection Against Viruses & Threats > Advanced Config… > Exclusions > Add or Remove > Add > Folder` and then select the folder. Or you can also paste that folder's path.

You should also check that article as it has other methods as well.

Excluding the CanonicalGroupLimited..... folder from my antivirus solved the problem for me.

@danieliser
Copy link

danieliser commented Jan 31, 2021

@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"
    }
  }
}

@danieliser
Copy link

danieliser commented Jan 31, 2021

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.

@danieliser
Copy link

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.

@SanderElias
Copy link

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?

@Arian8j2
Copy link

@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.

@sbin-github
Copy link

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?

@j0e1an
Copy link

j0e1an commented Oct 18, 2021

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.

@emadha
Copy link

emadha commented Feb 20, 2022

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.

@jhagege
Copy link

jhagege commented Feb 25, 2023

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.

@craigloewen-msft
Copy link
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.

@meydiwahendra
Copy link

meydiwahendra commented Sep 24, 2023

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

@DrorDvash
Copy link

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

@OneBlue
Copy link
Collaborator

OneBlue commented May 14, 2024

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.

@OneBlue OneBlue closed this as completed May 14, 2024
@bukowa
Copy link

bukowa commented Jun 26, 2024

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
Labels
Projects
None yet
Development

No branches or pull requests