Skip to content
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

move server loader controller from console to core; modify common server scheduler count to solve large cpu usage #4872

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
*/
public class RpcScheduledExecutor extends ScheduledThreadPoolExecutor {

public static final RpcScheduledExecutor TIMEOUT_SCHEDULER = new RpcScheduledExecutor(0,
public static final RpcScheduledExecutor TIMEOUT_SCHEDULER = new RpcScheduledExecutor(1,
"com.alibaba.nacos.remote.TimerScheduler");

public static final RpcScheduledExecutor COMMON_SERVER_EXECUTOR = new RpcScheduledExecutor(0,
public static final RpcScheduledExecutor COMMON_SERVER_EXECUTOR = new RpcScheduledExecutor(1,
"com.alibaba.nacos.remote.ServerCommonScheduler");

public RpcScheduledExecutor(int corePoolSize, final String threadName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ public Page<ConfigInfoBase> findAllConfigInfoBase(final int pageNo, final int pa
@Override
public Page<ConfigInfoWrapper> findAllConfigInfoForDumpAll(final int pageNo, final int pageSize) {
String sqlCountRows = "select count(*) from config_info";
String sqlFetchRows = " SELECT t.id,type,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified "
String sqlFetchRows = " SELECT t.id,type,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified "
+ " FROM ( SELECT id FROM config_info ORDER BY id LIMIT ?,? )"
+ " g, config_info t WHERE g.id = t.id ";
PaginationHelper<ConfigInfoWrapper> helper = createPaginationHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.console.controller;
package com.alibaba.nacos.core.controller;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.remote.RequestCallBack;
Expand All @@ -26,8 +26,6 @@
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.auth.common.ActionTypes;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.utils.RequestUtil;
import com.alibaba.nacos.console.security.nacos.NacosAuthConfig;
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.MemberUtil;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
Expand All @@ -36,6 +34,7 @@
import com.alibaba.nacos.core.remote.ConnectionManager;
import com.alibaba.nacos.core.remote.core.ServerLoaderInfoRequestHandler;
import com.alibaba.nacos.core.remote.core.ServerReloaderRequestHandler;
import com.alibaba.nacos.core.utils.Commons;
import com.alibaba.nacos.core.utils.RemoteUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -65,7 +64,7 @@
* @version $Id: ServerLoaderController.java, v 0.1 2020年07月22日 4:28 PM liuzunfei Exp $
*/
@RestController
@RequestMapping("/v1/console/loader")
@RequestMapping(Commons.NACOS_CORE_CONTEXT_V2 + "/loader")
public class ServerLoaderController {

private static final Logger LOGGER = LoggerFactory.getLogger(ServerLoaderController.class);
Expand All @@ -90,7 +89,7 @@ public class ServerLoaderController {
*
* @return state json.
*/
@Secured(resource = NacosAuthConfig.CONSOLE_RESOURCE_NAME_PREFIX + "loader", action = ActionTypes.READ)
@Secured(resource = Commons.NACOS_CORE_CONTEXT_V2 + "/loader", action = ActionTypes.READ)
@GetMapping("/current")
public ResponseEntity currentClients() {
Map<String, Connection> stringConnectionMap = connectionManager.currentClients();
Expand All @@ -102,7 +101,7 @@ public ResponseEntity currentClients() {
*
* @return state json.
*/
@Secured(resource = NacosAuthConfig.CONSOLE_RESOURCE_NAME_PREFIX + "loader", action = ActionTypes.WRITE)
@Secured(resource = Commons.NACOS_CORE_CONTEXT_V2 + "/loader", action = ActionTypes.WRITE)
@GetMapping("/reloadCurrent")
public ResponseEntity reloadCount(@RequestParam Integer count,
@RequestParam(value = "redirectAddress", required = false) String redirectAddress) {
Expand All @@ -116,13 +115,13 @@ public ResponseEntity reloadCount(@RequestParam Integer count,
*
* @return state json.
*/
@Secured(resource = NacosAuthConfig.CONSOLE_RESOURCE_NAME_PREFIX + "loader", action = ActionTypes.WRITE)
@Secured(resource = Commons.NACOS_CORE_CONTEXT_V2 + "/loader", action = ActionTypes.WRITE)
@GetMapping("/smartReloadCluster")
public ResponseEntity smartReload(HttpServletRequest request,
@RequestParam(value = "loaderFactor", required = false) String loaderFactorStr,
@RequestParam(value = "force", required = false) String force) {

LOGGER.info("Smart reload request receive,requestIp={}", RequestUtil.getRemoteIp(request));
LOGGER.info("Smart reload request receive,requestIp={}", getRemoteIp(request));

Map<String, Object> serverLoadMetrics = getServerLoadMetrics();
Object avgString = (Object) serverLoadMetrics.get("avg");
Expand Down Expand Up @@ -226,7 +225,7 @@ public void onException(Throwable e) {
*
* @return state json.
*/
@Secured(resource = NacosAuthConfig.CONSOLE_RESOURCE_NAME_PREFIX + "loader", action = ActionTypes.WRITE)
@Secured(resource = Commons.NACOS_CORE_CONTEXT_V2 + "/loader", action = ActionTypes.WRITE)
@GetMapping("/reloadClient")
public ResponseEntity reloadSingle(@RequestParam String connectionId,
@RequestParam(value = "redirectAddress", required = false) String redirectAddress) {
Expand All @@ -240,7 +239,7 @@ public ResponseEntity reloadSingle(@RequestParam String connectionId,
*
* @return state json.
*/
@Secured(resource = NacosAuthConfig.CONSOLE_RESOURCE_NAME_PREFIX + "loader", action = ActionTypes.READ)
@Secured(resource = Commons.NACOS_CORE_CONTEXT_V2 + "/loader", action = ActionTypes.READ)
@GetMapping("/cluster")
public ResponseEntity loaderMetrics() {

Expand Down Expand Up @@ -390,4 +389,19 @@ public void setMetric(Map<String, String> metric) {
}
}

private static String getRemoteIp(HttpServletRequest request) {
String xForwardedFor = request.getHeader(X_FORWARDED_FOR);
if (!org.apache.commons.lang3.StringUtils.isBlank(xForwardedFor)) {
return xForwardedFor.split(X_FORWARDED_FOR_SPLIT_SYMBOL)[0].trim();
}
String nginxHeader = request.getHeader(X_REAL_IP);
return org.apache.commons.lang3.StringUtils.isBlank(nginxHeader) ? request.getRemoteAddr() : nginxHeader;
}

private static final String X_REAL_IP = "X-Real-IP";

private static final String X_FORWARDED_FOR = "X-Forwarded-For";

private static final String X_FORWARDED_FOR_SPLIT_SYMBOL = ",";

}
5 changes: 5 additions & 0 deletions core/src/main/java/com/alibaba/nacos/core/utils/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public final class Commons {

public static final String NACOS_SERVER_VERSION = "/v1";

public static final String NACOS_SERVER_VERSION_V2 = "/v2";

public static final String DEFAULT_NACOS_CORE_CONTEXT = NACOS_SERVER_VERSION + "/core";

public static final String NACOS_CORE_CONTEXT = DEFAULT_NACOS_CORE_CONTEXT;

public static final String NACOS_CORE_CONTEXT_V2 = NACOS_SERVER_VERSION_V2 + "/core";


}