scylladb / scylla-jmx

Scylla JMX proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory Leak due to Client per request

ambantis opened this issue · comments

According to the docs for javax.ws.rs.client.Client:

Clients are heavy-weight objects that manage the client-side communication infrastructure. Initialization as well as disposal of a Client instance may be a rather expensive operation. It is therefore advised to construct only a small number of Client instances in the application. Client instances must be properly closed before being disposed to avoid leaking resources.

The current code creates this heavy-weight object per API Request:

https://github.com/scylladb/scylla-jmx/blob/branch-3.1/src/main/java/com/scylladb/jmx/api/APIClient.java#L90-L101:

    public Invocation.Builder get(String path, MultivaluedMap<String, String> queryParams) {
        Client client = ClientBuilder.newClient(new ClientConfig());
        WebTarget webTarget = client.target(getBaseUrl()).path(path);
        if (queryParams != null) {
            for (Entry<String, List<String>> qp : queryParams.entrySet()) {
                for (String e : qp.getValue()) {
                    webTarget = webTarget.queryParam(qp.getKey(), e);
                }
            }
        }
        return webTarget.request(MediaType.APPLICATION_JSON);
    }