Skip to content

fix: fixed yun api exceeds qps error #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"performance-now": "2.1.0",
"qs": "6.5.2",
"safe-buffer": "5.1.2",
"sleep": "^6.3.0",
"tough-cookie": "2.5.0",
"tunnel-agent": "0.6.0",
"uuid": "3.3.2",
Expand Down
7 changes: 4 additions & 3 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const request = require('../lib/request/index')
const crypto = require('crypto')
const cos = require('../lib/cos/cos')
const _ = require('lodash')
const sleep = require('sleep')

const DEFAULTS = {
signatureMethod: 'HmacSHA1',
Expand Down Expand Up @@ -497,7 +498,7 @@ class SlsMonitor {
}

async getCustomMetrics(region, announceInstance, rangeTime, period) {
const apiQPSLimit = 100
const apiQPSLimit = 80
const metricsRule = [
/^(GET|POST|DEL|DELETE|PUT|OPTIONS|HEAD)_([a-zA-Z0-9]+)_latency$/i,
/^(GET|POST|DEL|DELETE|PUT|OPTIONS|HEAD)_([a-zA-Z0-9]+)_(\d+)$/i,
Expand Down Expand Up @@ -555,7 +556,7 @@ class SlsMonitor {

if (!((i + 1) % apiQPSLimit)) {
if (i + 1 != apiQPSLimit) {
await SlsMonitor.sleep(1000)
sleep.sleep(1)
}
firstRequestFlag = false
results = await getMetricsResponse(requestHandlers)
Expand All @@ -569,7 +570,7 @@ class SlsMonitor {
return responses
}
if (!firstRequestFlag) {
await SlsMonitor.sleep(1000)
sleep.sleep(1)
}
results = await getMetricsResponse(requestHandlers)
results = this.cleanEmptyMetric(results, metricAttributeHash)
Expand Down