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

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

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

我的Chrome浏览器中出现相应的错误:

“MethodHubFrontend-1.1.0.js:32 POST http://cognitivehub.w3ibm.mybluemix.net/api/export/archive 500(内部服务器错误)”。

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

Cloudant标准中有一个选项,除了每秒提供50个查询,我们可以使用吗?

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

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

是的,你是对的。 您将需要升级到标准计划以提高费率限制。 请参阅Cloudant Web控制台的“ 帐户”选项卡中的详细信息以获取更多信息。

Cloudant标准中有一个选项,除了每秒提供50个查询,我们可以使用吗?

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

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

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

过去几天我也遇到同样的错误。 这是我正在使用的代码。 我认为这个问题与nodejs的asynchronous性质有关,并且没有正确地使用callback,所以代码/请求会同时发送,而不是同时发送。

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

我在Cloudant服务的每个请求之间等待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; }