morningman commented on a change in pull request #7474: URL: https://github.com/apache/incubator-doris/pull/7474#discussion_r781212291
########## File path: fe/fe-core/src/main/java/org/apache/doris/common/Config.java ########## @@ -713,6 +735,20 @@ @ConfField(mutable = true, masterOnly = true) public static int max_running_txn_num_per_db = 100; + /** + * maximum QPS of total system, + * new query will be rejected if QPS exceeds the threshold. + */ + @ConfField(mutable = true, masterOnly = true, callback = QueryLimiterConfHandler.class) Review comment: I think this is not `masterOnly`? ########## File path: fe/fe-core/src/main/java/org/apache/doris/http/rest/LoadAction.java ########## @@ -116,6 +118,15 @@ public void executeWithoutPassword(BaseRequest request, BaseResponse response) t } redirectAddr = execEnv.getMultiLoadMgr().redirectAddr(fullDbName, label); } else { + // Check rate limiter. + MasterRpcExecutor executor = new MasterRpcExecutor(ConnectContext.get()); + try { + if (!executor.checkRateLimiter(TLimiterType.STREAM_LOAD)) { + throw new Exception("Check stream load rate limiter returned fail!"); Review comment: How about return detail error msg? And better to throw exception directly from `checkRateLimiter()` ########## File path: fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java ########## @@ -335,6 +336,19 @@ private void dispatch() throws IOException { LOG.warn("Unknown command(" + command + ")"); return; } + // check rate limiter. + try { + MasterRpcExecutor executor = new MasterRpcExecutor(ctx); Review comment: 1. `dispatch()` is not always QUERY 2. it is not good send rpc to master FE for each request. ########## File path: fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/UserProperty.java ########## @@ -501,6 +535,9 @@ public void write(DataOutput out) throws IOException { // user resource resource.write(out); + // user limiter + limiter.write(out); Review comment: You need to put all properties into `commonProperties`, so that you don't need to add new field for persistence. You can refer to `cpu_resource_limit` ########## File path: fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/UserProperty.java ########## @@ -17,6 +17,7 @@ package org.apache.doris.mysql.privilege; +import com.google.common.util.concurrent.AtomicDouble; Review comment: pay attention to the import order ########## File path: fe/fe-core/src/main/java/org/apache/doris/system/RateLimiterMgr.java ########## @@ -0,0 +1,100 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.system; + +import com.google.common.collect.Maps; +import com.google.common.util.concurrent.RateLimiter; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.mysql.privilege.UserProperty; +import org.apache.doris.thrift.TLimiterType; + +import java.util.Map; + +/** + * RateLimiterMgr collect all rate limiter of the system. + */ +public class RateLimiterMgr { + private RateLimiter systemQPSLimiter; + private RateLimiter systemStreamLoadLimiter; + private Map<String, RateLimiter> userToQPSLimiter; + private Map<String, RateLimiter> userToStreamLoadLimiter; + + public RateLimiterMgr(double QPS, double streamLoadPS) { + this.systemQPSLimiter = RateLimiter.create(QPS); + this.systemStreamLoadLimiter = RateLimiter.create(streamLoadPS); + this.userToQPSLimiter = Maps.newConcurrentMap(); + this.userToStreamLoadLimiter = Maps.newConcurrentMap(); + } + + public synchronized boolean checkRateLimiter(TLimiterType type, String user) { Review comment: why using `synchronized`? the RateLimiter is thread safe ########## File path: fe/fe-core/src/main/java/org/apache/doris/system/RateLimiterMgr.java ########## @@ -0,0 +1,100 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.system; + +import com.google.common.collect.Maps; +import com.google.common.util.concurrent.RateLimiter; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.mysql.privilege.UserProperty; +import org.apache.doris.thrift.TLimiterType; + +import java.util.Map; + +/** + * RateLimiterMgr collect all rate limiter of the system. + */ +public class RateLimiterMgr { + private RateLimiter systemQPSLimiter; + private RateLimiter systemStreamLoadLimiter; + private Map<String, RateLimiter> userToQPSLimiter; + private Map<String, RateLimiter> userToStreamLoadLimiter; + + public RateLimiterMgr(double QPS, double streamLoadPS) { Review comment: It is not recommended to pass these values through the constructor's parameters. If we subsequently add more limiter, there will be more arguments to the constructor. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org