use of com.baidu.hugegraph.define.WorkLoad in project incubator-hugegraph by apache.
the class LoadReleaseFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
if (LoadDetectFilter.isWhiteAPI(requestContext)) {
return;
}
WorkLoad load = this.loadProvider.get();
load.decrementAndGet();
}
use of com.baidu.hugegraph.define.WorkLoad in project incubator-hugegraph by apache.
the class LoadDetectFilter method filter.
@Override
public void filter(ContainerRequestContext context) {
if (LoadDetectFilter.isWhiteAPI(context)) {
return;
}
HugeConfig config = this.configProvider.get();
int maxWorkerThreads = config.get(ServerOptions.MAX_WORKER_THREADS);
WorkLoad load = this.loadProvider.get();
// There will be a thread doesn't work, dedicated to statistics
if (load.incrementAndGet() >= maxWorkerThreads) {
throw new ServiceUnavailableException(String.format("The server is too busy to process the request, " + "you can config %s to adjust it or try again later", ServerOptions.MAX_WORKER_THREADS.name()));
}
long minFreeMemory = config.get(ServerOptions.MIN_FREE_MEMORY);
long allocatedMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long presumableFreeMem = (Runtime.getRuntime().maxMemory() - allocatedMem) / Bytes.MB;
if (presumableFreeMem < minFreeMemory) {
gcIfNeeded();
throw new ServiceUnavailableException(String.format("The server available memory %s(MB) is below than " + "threshold %s(MB) and can't process the request, " + "you can config %s to adjust it or try again later", presumableFreeMem, minFreeMemory, ServerOptions.MIN_FREE_MEMORY.name()));
}
}
Aggregations