Java Grizzly HTTP服务器在某些线程上达到100%的CPU使用率,工作能力已满。

huangapple 未分类评论52阅读模式
英文:

Java Grizzly HTTP Server working to capacity 100% CPU usage on some threads

问题

我正在使用Grizzly Http Server在我的Web服务器上提供REST API。经过一段时间,服务器的负载越来越高,即使没有更多的用户在线。

htop中,我可以看到有一些Grizzly Http线程(在图片中是一个),它们正在使用一个内核的100%。这是怎么可能的?有什么想法吗?

代码:

/* IMPORTS */

public class WebAppServer {

    private static WebAppServer instance;

    public static WebAppServer getInstance() {
        if (instance == null) instance = new WebAppServer();
        return instance;
    }

    public void start() throws IOException, URISyntaxException {
        String baseUrl = MavenPropertyDao.getInstance().getProperty(MavenPropertyDao.REST_SERVER_URL);
        ResourceConfig rc = new MyConfig();
        rc.register(new CORSFilter());
        rc.registerClasses(/* REST CLASSES */);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(new URI(baseUrl), rc);
        Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
        server.start();
    }


    public class MyConfig extends ResourceConfig {
        public MyConfig() {
            register(new HttpExceptionHandler());
            register(MultiPartFeature.class);
            register(GsonProvider.class);
            property(ServerProperties.MONITORING_STATISTICS_ENABLED, true);
        }
    }

}

一天后的htop截图:

Java Grizzly HTTP服务器在某些线程上达到100%的CPU使用率,工作能力已满。

英文:

Im using the Grizzly Http Server on my webserver to serve a REST API. After some time the server is working more and more to full capacity even there are no more users online.

In htop i can see that there are some grizzly http threads (at this time in the picture one) which are using 100% of one kernal. How is that possible? Any ideas?

Code:

/* IMPORTS */

public class WebAppServer {

    private static WebAppServer instance;

    public static WebAppServer getInstance() {
        if (instance == null) instance = new WebAppServer();
        return instance;
    }

    public void start() throws IOException, URISyntaxException {
        String baseUrl = MavenPropertyDao.getInstance().getProperty(MavenPropertyDao.REST_SERVER_URL);
        ResourceConfig rc = new MyConfig();
        rc.register(new CORSFilter());
        rc.registerClasses(/* REST CLASSES */);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(new URI(baseUrl), rc);
        Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
        server.start();
    }


    public class MyConfig extends ResourceConfig {
        public MyConfig() {
            register(new HttpExceptionHandler());
            register(MultiPartFeature.class);
            register(GsonProvider.class);
            property(ServerProperties.MONITORING_STATISTICS_ENABLED, true);
        }
    }

}

htop after a day:
Java Grizzly HTTP服务器在某些线程上达到100%的CPU使用率,工作能力已满。

huangapple
  • 本文由 发表于 2020年4月9日 14:23:36
  • 转载请务必保留本文链接:https://java.coder-hub.com/61115122.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定