我在Bluemix和Cloudant Lite服务上的Node.js web应用程序中收到一个500查询错误



当我执行某个函数从相关的web应用程序访问Cloudant数据库时,我在Node.js控制台窗口中收到以下错误:

"错误:您已经超过了查询类每秒5个请求的当前限制"。

我在Chrome浏览器中收到了相应的错误:

"MethodHubFrontend1.1.0.js:32 POSThttp://cognitivehub.w3ibm.mybluemix.net/api/export/archive500(内部服务器错误)".

我们的应用程序正在Bluemix Dedicated(CIO)上运行,带有Cloudant Lite服务。是什么导致了这些错误?是因为我们超过了Cloudant Lite中每秒5个查询的吞吐量限制吗?

除了每秒提供50个查询的选项之外,Cloudant Standard中还有其他选项吗?

我们应该如何处理Node.js服务器中的错误,使其返回3xx错误代码而不是500错误代码?

是什么导致了这些错误?是因为我们超过了Cloudant Lite中每秒5个查询的吞吐量限制吗?

是的,你是对的。您需要升级到标准计划以提高费率限制。有关更多信息,请查看Cloudant web控制台中帐户选项卡中的详细信息。

Cloudant Standard中除了每秒提供50个查询的选项之外,还有其他选项可以使用吗?

有几个级别,如帐户容量选项卡中所列。

此外,我们应该如何处理Node.js服务器中的错误,使其返回3xx错误代码而不是500错误代码?

Cloudant应返回HTTP代码429(请求太多)。您的应用程序可以通过两种方式对此错误情况作出响应-失败或重新发送请求。

过去几天我遇到了同样的错误。这是我正在使用的代码。我认为这个问题与nodejs的异步性质有关,并且没有正确使用回调,因此代码/请求是同步发送的,而不是同时异步发送的。

错误:您已经超过了查询类每秒5次请求的当前限制

我在向Cloudant Service发出每个请求之间等待1秒。我认为服务出了问题。

// Used to add sleep time between calls to cloudant
var sleep = require('sleep'); 
const winston = require('winston')
var action_result = null
winston.level = 'debug';
var dbCredentials = {
dbName: 'testdb'
};
var feed = 1;
//Intialize DB for putting records in Cloudant.
dbCredentials.url = "https://replace with your URL-bluemix:replacewith your URL-bluemix.cloudant.com";
cloudant = require('cloudant')(dbCredentials.url);
// check if DB exists if not create a  testdb database
cloudant.db.create(dbCredentials.dbName, function(err, data) {
winston.log("debug","create a test database Error:", err);
winston.log("debug","create a test database Data:", data);      
});
dbnames = cloudant.db.use(dbCredentials.dbName);
winston.log("debug","Creating a record in  database %s" , dbCredentials.dbName);
//  Insert a one second timeout delay to not exceed 5 queries every 1 second in Cloudant API
winston.log("debug","Reproduce timeout error First SLEEP 5 minutes---------------  FIND Time is %d ", new Date().getTime() / 1000 );
sleep.sleep(1);
//Check if the asset action already exists.
dbnames.find({selector:{feed:feed }}, function(er, action_result) {
sleep.sleep(5);
if (er) {
winston.log("debug",'[db.find]  Error Message %s', er.message);
throw er;
}
});
if ( action_result !== null) {
winston.log("debug",'Reproduce timeout error found results %d documents.', action_result.docs.length);
return action_result;
}else{
winston.log("debug",'Reproduce timeout error before loop');
for (var i = 0; i < 1000; i++) {
winston.log("debug","Reproduce timeout error SLEEP item %d ---------------  FIND Time is %d " ,i,  new Date().getTime() / 1000 );
sleep.sleep(1);
dbnames.insert(docData (i, new Date().getTime() / 1000),     function(err, body, header) {
if (err) {
return winston.log("debug",'[db.insert] ', err.message);
}       
winston.log("debug",'You have inserted the doc.');
expert_exists = false;
});
}; //End Loop
}; //End Else
function docData (number, timestring) {
var responseData = {
feed : number,
time : timestring,
};   
return responseData;  
}

最新更新