Node.js Google云存储节点加载多个读取请求太慢
你好! 我试图弄清楚为什么对我的图像API的一些请求(通常是最后的请求)需要超过1分钟才能加载。第一个基本上是瞬时的。在互联网上到处搜索,但还没有合适的答案。我使用谷歌云在服务器上存储图像和节点,服务器将图像作为缓冲写入头提供给浏览器 你可以查看我在说什么访问该网站(18年前的内容): 正如您所看到的,有些图像无法正确加载。我很担心,因为这个网站预计将在全世界拥有数千个以上的个人资料 我使用PM2处理服务器端的服务(2GB可用内存)。这是桌子:Node.js Google云存储节点加载多个读取请求太慢,node.js,reactjs,google-cloud-storage,buffer,Node.js,Reactjs,Google Cloud Storage,Buffer,你好! 我试图弄清楚为什么对我的图像API的一些请求(通常是最后的请求)需要超过1分钟才能加载。第一个基本上是瞬时的。在互联网上到处搜索,但还没有合适的答案。我使用谷歌云在服务器上存储图像和节点,服务器将图像作为缓冲写入头提供给浏览器 你可以查看我在说什么访问该网站(18年前的内容): 正如您所看到的,有些图像无法正确加载。我很担心,因为这个网站预计将在全世界拥有数千个以上的个人资料 我使用PM2处理服务器端的服务(2GB可用内存)。这是桌子: ┌─────┬─────────────────
┌─────┬─────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 7 │ ServiceAfiliado │ default │ 1.0.0 │ fork │ 31312 │ 20m │ 3 │ online │ 0% │ 55.9mb │ root │ disabled │
│ 0 │ ServiceAvaliacao │ default │ 1.0.0 │ fork │ 31249 │ 20m │ 3 │ online │ 0% │ 55.2mb │ root │ disabled │
│ 8 │ ServiceBlog │ default │ 1.0.0 │ fork │ 31330 │ 20m │ 3 │ online │ 0% │ 61.1mb │ root │ disabled │
│ 1 │ ServiceChat │ default │ 1.0.0 │ fork │ 31256 │ 20m │ 3 │ online │ 0% │ 57.3mb │ root │ disabled │
│ 9 │ ServiceConfig │ default │ 1.0.0 │ fork │ 31337 │ 20m │ 3 │ online │ 0% │ 56.2mb │ root │ disabled │
│ 10 │ ServiceImage │ default │ 1.0.0 │ fork │ 31904 │ 0s │ 13 │ online │ 0% │ 19.1mb │ root │ disabled │
│ 2 │ ServiceLead │ default │ 1.0.0 │ fork │ 31269 │ 20m │ 3 │ online │ 0% │ 54.8mb │ root │ disabled │
│ 3 │ ServiceMail │ default │ 1.0.0 │ fork │ 31276 │ 20m │ 3 │ online │ 0% │ 43.3mb │ root │ disabled │
│ 4 │ ServicePagamento │ default │ 1.0.0 │ fork │ 31289 │ 20m │ 3 │ online │ 0% │ 42.5mb │ root │ disabled │
│ 5 │ ServiceParceiro │ default │ 1.0.0 │ fork │ 31296 │ 20m │ 3 │ online │ 0% │ 60.1mb │ root │ disabled │
│ 6 │ ServicePerfil │ default │ 1.0.0 │ fork │ 31309 │ 20m │ 3 │ online │ 0% │ 69.7mb │ root │ disabled │
└─────┴─────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
处理此特定请求的路由:
router.get('/image/:imageId', async function (req, res) {
try {
let imageId = req.param('imageId')
let returnImage = await cloudController.getImageFromBucket('fotos_perfil', imageId)
res.writeHead(200, {'Content-Type': 'image/jpg'});
returnImage.on('data', (data) => {
res.write(data)
})
returnImage.on('error', (error) => {
res.status(400).send('Erro lendo a imagem')
console.error(error)
})
returnImage.on('end', () => {
res.end()
})
} catch (err) {
res.status(500).send('Internal Server Error')
}
})
以及关联的控制器:
async function getImageFromBucket(bucket, imageId) {
return new Promise((resolve, reject) => {
try {
let imageInfo = storage.bucket(bucket).file(imageId).createReadStream()
resolve(imageInfo)
} catch (e) {
reject(e)
}
})
}
有人能给我一些解决这个问题的办法吗?我已经阅读了谷歌官方文档,提示是使用fast-crc32c
,但仅限于此。没有关于如何配置的线索