- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我真的对此迷失了,我尝试了很多事情,例如更改超时、使用不同的库等,我希望有人能明白为什么在给我带来麻烦的实际代码中会发生这种情况。我会尽量简洁。
快速文字说明:
工作人员从队列中选择一个作业,使用一个模块,并向其传输所有必需的信息。然后,该模块使用 axios 将所有请求的 Promise.all 发送到另一个微服务。然后,该微服务向我无法控制的服务发出另一个 https 请求,这通常需要很长时间才能应答(1-10 分钟)。该服务应返回一个文档,然后微服务会将其返回给工作人员使用的模块。
在等待缓慢的服务响应微服务时,事件循环似乎无法响应 kubernetes 进行的运行状况检查。
代码:
worker 模块:
const axios = require('axios');
const { getVariableValue } = require("redacted");
const logger = require('redacted');
const https = require('https')
module.exports = webApiOptiDocService = {
async getDocuments(docIDs, transactionId, timeStamp) {
try {
var documents = [];
await Promise.all(docIDs.map(async (docID) => {
var document = await axios.post(getVariableValue("GET_DOCUMENT_SERVICE_URL"), docID, {
httpsAgent: new https.Agent({
rejectUnauthorized: false,
keepAlive: true
}),
auth: {
username: getVariableValue("WEBAPI_OPTIDOCS_SERVICE_USERNAME"),
password: getVariableValue("WEBAPI_OPTIDOCS_SERVICE_PASSWORD")
},
headers: {
"x-global-transaction-id": transactionId,
"timeStamp": timeStamp
}
});
documents.push(document.data.content);
}));
return documents
}
catch (err) {
const responseData = err.response ? err.response.data : err.message
throw Error(responseData)
}
}
}
这是获取这些请求的微服务:
API:
const express = require('express');
const router = express.Router();
const logger = require('redacted');
const getDocuemntService = require('./getDocumentService')
var clone = require('clone')
module.exports = router.post('/getDocument', async (req, res, next) => {
try {
var transactionId = req.headers["x-global-transaction-id"]
var timeStamp = req.headers["timestamp"]
var document = await getDocuemntService(req.body, transactionId, timeStamp);
var cloneDocument = clone(document)
res.status(200);
res.json({
statusDesc: "Success",
status: true,
content: cloneDocument
});
}
catch (err) {
res.status(500).send("stack: " + err.stack + "err: " + err.message + " fromgetdocument")
}
});
这是它随后使用的 getDocument.js 模块:
const axios = require('axios');
const { getVariableValue } = require("redacted");
const logger = require('redacted');
const https = require('https')
const fileType = require('file-type')
var request = require('request-promise-native')
module.exports = async (docID, transactionId, timeStamp) => {
try {
var startTime = Date.now();
const documentBeforeParse = await request.get(getVariableValue("WEBAPI_OPTIDOCS_SERVICE_URL_GET") + docID.docID, {
strictSSL: false,
headers: {
'x-global-transaction-id': transactionId
},
timeout: Infinity
}).auth(getVariableValue("WEBAPI_OPTIDOCS_SERVICE_USERNAME"), getVariableValue("WEBAPI_OPTIDOCS_SERVICE_PASSWORD"))
const parsedDocument = JSON.parse(documentBeforeParse)
var document = {
data: {
mimeType: parsedDocument.mimeType,
fileName: "",
content: parsedDocument.content
}
}
// const document = await axios.get(getVariableValue("WEBAPI_OPTIDOCS_SERVICE_URL_GET") + docID.docID, {
// maxContentLength: 524288000, //500 MB in Bytes
// maxBodyLength: 524288000, //500 MB in Bytes
// method: 'get',
// httpsAgent: new https.Agent({
// rejectUnauthorized: false
// }),
// auth: {
// username: getVariableValue("WEBAPI_OPTIDOCS_SERVICE_USERNAME"),
// password: getVariableValue("WEBAPI_OPTIDOCS_SERVICE_PASSWORD")
// },
// headers: {
// 'x-global-transaction-id': transactionId
// }
// });
if (document.data.mimeType == "") {
if (recoverMimeType(document.data.content)) {
document.data.mimeType = recoverMimeType(document.data.content).ext
}
else {
throw Error("Missing mime type can not be recovered.")
}
}
var fixedMimeType = fixMimeType(document.data.mimeType);
document.data.fileName = docID.docPartsPrefixName + fixedMimeType
var returnDocument = {
fileName: document.data.fileName,
content: document.data.content,
mimeType: document.data.mimeType
}
return returnDocument;
}
catch (error) {
throw Error(error);
}
}
function fixMimeType(mimeType) {
return "." + mimeType
}
function recoverMimeType(content) {
return fileType.fromBuffer(Buffer.from(content[0], "base64"))
}
我删除了所有记录器,但保留了注释掉的 axios 请求,我尝试将其替换为 Request 以测试这是否与它有关。
基本上,微服务通过 Promise.all 获取 50-150 个请求,在获取相当多的请求后,最终会因为非常慢的答案而消失,因为它不会回答健康检查。
最佳答案
对于任何遇到这个问题并寻找答案的人来说,我最终解决这个问题的方法是大幅增加我的应用程序从 kubernetes 获取的内存。看来这不是事件循环问题,而是性能问题。祝你好运!
关于javascript - 在等待 HTTPS 请求时,事件循环被卡住并且不会响应健康检查 - NodeJS+kubernetes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59837792/
尝试使用集成到 QTCreator 的表单编辑器,但即使我将插件放入 QtCreator.app/Contents/MacOS/designer 也不会显示。不过,相同的 dylib 文件确实适用于独
在此代码示例中。 “this.method2();”之后会读到什么?在返回returnedValue之前会跳转到method2()吗? public int method1(int returnedV
我的项目有通过gradle配置的依赖项。我想添加以下依赖项: compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', v
我将把我们基于 Windows 的客户管理软件移植到基于 Web 的软件。我发现 polymer 可能是一种选择。 但是,对于我们的使用,我们找不到 polymer 组件具有表格 View 、下拉菜单
我的项目文件夹 Project 中有一个文件夹,比如 ED 文件夹,当我在 Eclipse 中指定在哪里查找我写入的文件时 File file = new File("ED/text.txt"); e
这是奇怪的事情,这个有效: $('#box').css({"backgroundPosition": "0px 250px"}); 但这不起作用,它只是不改变位置: $('#box').animate
这个问题在这里已经有了答案: Why does OR 0 round numbers in Javascript? (3 个答案) 关闭 5 年前。 Mozilla JavaScript Guide
这个问题在这里已经有了答案: Is the function strcmpi in the C standard libary of ISO? (3 个答案) 关闭 8 年前。 我有一个问题,为什么
我目前使用的是共享主机方案,我不确定它使用的是哪个版本的 MySQL,但它似乎不支持 DATETIMEOFFSET 类型。 是否存在支持 DATETIMEOFFSET 的 MySQL 版本?或者有计划
研究 Seam 3,我发现 Seam Solder 允许将 @Named 注释应用于包 - 在这种情况下,该包中的所有 bean 都将自动命名,就好像它们符合条件一样@Named 他们自己。我没有看到
我知道 .append 偶尔会增加数组的容量并形成数组的新副本,但 .removeLast 会逆转这种情况并减少容量通过复制到一个新的更小的数组来改变数组? 最佳答案 否(或者至少如果是,则它是一个错
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
noexcept 函数说明符是否旨在 boost 性能,因为生成的对象中可能没有记录异常的代码,因此应尽可能将其添加到函数声明和定义中?我首先想到了可调用对象的包装器,其中 noexcept 可能会产
我正在使用 Angularjs 1.3.7,刚刚发现 Promise.all 在成功响应后不会更新 angularjs View ,而 $q.all 会。由于 Promises 包含在 native
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我正在编写一个玩具(物理)矢量库,并且遇到了 GHC 坚持认为函数应该具有 Integer 的问题。是他们的类型。我希望向量乘以向量以及标量(仅使用 * ),虽然这可以通过仅使用 Vector 来实现
PHP 的 mail() 函数发送邮件正常,但 Swiftmailer 的 Swift_MailTransport 不起作用! 这有效: mail('user@example.com', 'test
我尝试通过 php 脚本转储我的数据,但没有命令行。所以我用 this script 创建了我的 .sql 文件然后我尝试使用我的脚本: $link = mysql_connect($host, $u
使用 python 2.6.4 中的 sqlite3 标准库,以下查询在 sqlite3 命令行上运行良好: select segmentid, node_t, start, number,title
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我是一名优秀的程序员,十分优秀!