Firebase实时数据库的同时连接数有一个上限,但超出限制时会发生什么?
Firebase实时数据库在使用JavaScript从Web访问时的行为如何? 发生以下哪种情况:取消连接或等待连接连接?
自我解决
我试过,连接被取消了。
代码是nodejs。
import firebase from 'firebase'
import log4js from 'log4js'
const logger = log4js.getLogger();
const config = {
apiKey: "xxxxxxxxx",
authDomain: "xxxxxxxx",
databaseURL: "https://xxxxxxxxxxxxxxxxxx.firebaseio.com",
};
let apps = [];
function connect(app_name) {
const app = firebase.initializeApp(config, app_name);
apps = [...apps, app];
const database = app.database();
database.ref(".info/connected").on("value", (snapshot) => {
logger.info(`${app_name} status: ${snapshot.val()}`);
})
}
for(let i = 0; i<100; i++) {
const client_name = `client-${i}`;
connect(client_name)
}
setTimeout(() => connect('client-100'), 4000);
setTimeout(() => connect('client-101'), 5000);
setTimeout(() => apps[0].database().goOffline(), 6000);
setTimeout(() => connect('client-102'), 7000);
尾输出:
[2017-03-10 18:56:39.094] [INFO] [default] - client-2 status: true
[2017-03-10 18:56:39.432] [INFO] [default] - client-100 status: false
FIREBASE WARNING: Specified Firebase database has reached its Peak Connections limit. If you are the Firebase owner, consider upgrading. (https://free-check.firebaseio.com)
[2017-03-10 18:56:40.431] [INFO] [default] - client-101 status: false
FIREBASE WARNING: Specified Firebase database has reached its Peak Connections limit. If you are the Firebase owner, consider upgrading. (https://free-check.firebaseio.com)
[2017-03-10 18:56:41.435] [INFO] [default] - client-0 status: false
[2017-03-10 18:56:42.431] [INFO] [default] - client-102 status: false
[2017-03-10 18:56:43.013] [INFO] [default] - client-102 status: true