use of com.actiontech.dble.backend.ConQueue in project dble by actiontech.
the class PhysicalDatasource method closeByIdleMany.
private void closeByIdleMany(int idleCloseCount, int idleCons) {
LOGGER.info("too many ilde cons ,close some for datasouce " + name + " want close :" + idleCloseCount + " total idle " + idleCons);
List<BackendConnection> readyCloseCons = new ArrayList<BackendConnection>(idleCloseCount);
for (ConQueue queue : conMap.getAllConQueue()) {
int closeNumber = (queue.getManCommitCons().size() + queue.getAutoCommitCons().size()) * idleCloseCount / idleCons;
readyCloseCons.addAll(queue.getIdleConsToClose(closeNumber));
}
for (BackendConnection idleCon : readyCloseCons) {
if (idleCon.isBorrowed()) {
LOGGER.info("find idle con is using " + idleCon);
}
idleCon.close("too many idle con");
}
}
use of com.actiontech.dble.backend.ConQueue in project dble by actiontech.
the class PhysicalDatasource method getIdleCountForSchema.
public int getIdleCountForSchema(String schema) {
ConQueue queue = conMap.getSchemaConQueue(schema);
int total = 0;
total += queue.getAutoCommitCons().size() + queue.getManCommitCons().size();
return total;
}
use of com.actiontech.dble.backend.ConQueue in project dble by actiontech.
the class PhysicalDatasource method connectionHeatBeatCheck.
public void connectionHeatBeatCheck(long conHeartBeatPeriod) {
// to die
if (dying.get()) {
closeByDyingAll();
return;
}
long hearBeatTime = TimeUtil.currentTimeMillis() - conHeartBeatPeriod;
for (ConQueue queue : conMap.getAllConQueue()) {
longIdleHeartBeat(queue.getAutoCommitCons(), hearBeatTime);
longIdleHeartBeat(queue.getManCommitCons(), hearBeatTime);
}
// the following is about the idle connection number control
int idleCons = getIdleCount();
int activeCons = this.getActiveCount();
int createCount = (hostConfig.getMinCon() - idleCons) / 3;
// create if idle too little
if ((createCount > 0) && (idleCons + activeCons < size)) {
createByIdleLittle(idleCons, createCount);
} else if (idleCons > hostConfig.getMinCon()) {
closeByIdleMany(idleCons - hostConfig.getMinCon(), idleCons);
} else {
int activeCount = this.getActiveCount();
if (activeCount > size) {
String s = Alarms.DEFAULT + "DATASOURCE EXCEED [name=" + name + ",active=" + activeCount + ",size=" + size + ']';
LOGGER.info(s);
}
}
}
use of com.actiontech.dble.backend.ConQueue in project dble by actiontech.
the class PhysicalDatasource method returnCon.
private void returnCon(BackendConnection c) {
if (dying.get()) {
c.close("dying");
closeByDyingAll();
return;
}
c.setAttachment(null);
c.setBorrowed(false);
c.setLastTime(TimeUtil.currentTimeMillis());
ConQueue queue = this.conMap.getSchemaConQueue(c.getSchema());
boolean ok = false;
if (c.isAutocommit()) {
ok = queue.getAutoCommitCons().offer(c);
} else {
ok = queue.getManCommitCons().offer(c);
}
if (!ok) {
LOGGER.info("can't return to pool ,so close con " + c);
c.close("can't return to pool ");
}
}
use of com.actiontech.dble.backend.ConQueue in project dble by actiontech.
the class PhysicalDatasource method takeCon.
private BackendConnection takeCon(BackendConnection conn, String schema) {
conn.setBorrowed(true);
if (!conn.getSchema().equals(schema)) {
// need do schema syn in before sql send
conn.setSchema(schema);
}
ConQueue queue = conMap.getSchemaConQueue(schema);
queue.incExecuteCount();
// update last time, the schedule job will not close it
conn.setLastTime(System.currentTimeMillis());
return conn;
}
Aggregations