提高axios的下载速度 [英] Improve axios get download speed
问题描述
我正在使用 axios
从Azure存储Blob下载文件(〜100MB).
I am using axios
to download a file (~100MB) from an Azure Storage Blob.
axios({
method: 'get',
url: uri,
onDownloadProgress: (progressEvent) => {
console.log("Loaded: " + ((progressEvent.loaded / progressEvent.total) * 100) + "%");
},
responseType: 'arraybuffer'
}).then({})
我的问题是实际下载文件要花费相当长的时间(约10分钟).我以前使用的fetch()比这还要慢(〜15-20分钟).你们对加快下载速度有什么建议吗?我的网速不是问题,因为直接下载文件或使用Azure Storage Explorer(1.12.0,AzCopy 10.3.3)只需不到2分钟的时间.
My problem is that it is taking quite a while to actually download the file (~10 minutes). I was previously using fetch() which was slower than this even (~15-20 minutes). Are there any recommendations you guys have on how to speed up the download? My internet speed isn't the problem, as downloading the file directly or using the Azure Storage Explorer(1.12.0, AzCopy 10.3.3) takes less than 2 minutes.
我也尝试过使用azure-storage的blobServiceClient,但是获得了与axios和fetch相似的速度(大约15kbps).
I also tried using azure-storage's blobServiceClient, but got similar speeds to axios and fetch (roughly 15kbps).
如果有帮助,它位于React应用程序中.
This is in a React app if that helps.
推荐答案
我已经测试了下载速度.希望我的结果对您有用.
I have test the speed of download. I hope my result can useful to you.
- 我将
StorageExplorer.exe
上载为源文件以进行下载测试.文件大小为92.5M.
- I upload
StorageExplorer.exe
as source file for download test. The size of file is 92.5M.
- 通过
Azure Storage Explore
下载文件,将花费1分零7秒
.
- Download file by
Azure Storage Explore
, it will took1 minute and 07 seconds
.
- 通过chrome浏览器在门户网站中下载文件,这将花费
58秒
.
- 通过我的测试代码下载文件.
①从 portal
或 Storage Explore
复制网址.
① Copy Url from portal
or Storage Explore
.
网址类似: https://p*****ge.blob.core.windows.net/testcontainer/StorageExplorer.exe
通过我的代码进行测试后,需要花费 1分52秒
,并且非常不稳定,有时测试下载时间会更长.
After test by my code, it will took 1 minute and 52 seconds
and it is very unstable, sometimes the test download time will be longer.
②从 AzCopy命令
复制网址.
② Copy Url from AzCopy Command
.
URL格式如下: https://pan********ge.blob.core.windows.net/testcontainer/StorageExplorer.exe?se = 2020-09-18T07%3A55%3A28Z& sp = rl& sv = 2018-03-28& sr = c& sig = 5kJyTBwHHRS ****** mlj3%2FWj9CmvQriXCMi4%3D
通过相同的代码进行测试后,将花费 1分钟零02秒
.
After test by same code, it will took 1 minute and 02 seconds
.
我的测试结论:
请勿使用类似于 https://p*****ge.blob.core.windows.net/testcontainer/StorageExplorer.exe
的网址.
Don't use url which look like https://p*****ge.blob.core.windows.net/testcontainer/StorageExplorer.exe
.
您可以使用类似于从AzCopy命令获取的网址.
下面是我的测试代码.
- 我进步了
- npm i axios
'use strict'
const Fs = require('fs')
const Path = require('path')
const Axios = require('axios')
const ProgressBar = require('progress')
async function download () {
const url = 'https://pan*****e.blob.core.windows.net/testcontainer/StorageExplorer.exe'
console.log('Connecting …')
const { data, headers } = await Axios({
url,
method: 'GET',
responseType: 'stream'
})
const totalLength = headers['content-length']
console.log('Starting download')
const progressBar = new ProgressBar('-> downloading [:bar] :percent :etas', {
width: 40,
complete: '=',
incomplete: ' ',
renderThrottle: 1,
total: parseInt(totalLength)
})
const writer = Fs.createWriteStream(
Path.resolve(__dirname, 'software', 'StorageExplorer.exe')
)
data.on('data', (chunk) => progressBar.tick(chunk.length))
data.pipe(writer)
}
download()
这篇关于提高axios的下载速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!