Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

BUG Memory leak when use agent

Đang mở
#135 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
observability-sre

Hướng nghiên cứu

Bắt đầu từ lời gọi PyroscopeAgent.start và theo dõi cách agent xử lý các snapshot lặp lại cũng như phần triển khai tùy chỉnh của GalileoProfileExporter.export. Tái hiện báo cáo bằng cấu hình 0.12.0 được cung cấp và giám sát bộ nhớ trong khi các lần tải lên đang chạy. Công việc được xem là hoàn tất khi đã xác định được nguồn gây tăng bộ nhớ kéo dài và agent không còn giữ lại dữ liệu profiling đã hoàn tất một cách ngoài dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I use 0.12.0 agent upload JFR data to my backend.

<dependency>
            <groupId>io.pyroscope</groupId>
            <artifactId>agent</artifactId>
            <version>0.12.0</version>
 </dependency>

Upload code:

Config profileConfig = new Config.Builder()
                    .setFormat(Format.JFR)
                    .setLogLevel(Logger.Level.INFO)
                    .setProfilingEvent(EventType.ITIMER)
                    .setProfilingAlloc("0")
                    .setProfilingInterval(Duration.ofMillis(10))
                    .setUploadInterval(Duration.ofSeconds(5))
                    .build();
GalileoProfileExporter exporter = new GalileoProfileExporter(resource, DEFAULT_RETRY);
PyroscopeAgent.start(new PyroscopeAgent.Options.Builder(profileConfig).setExporter(exporter).build());

My exporter:

public class GalileoProfileExporter implements Exporter {
    private static final Duration TIMEOUT = Duration.ofSeconds(10);
    private static final String ENDPOINT = "https://xxxxxxxxxxxxx";

    final Ocp.Resource resource;
    final int ingestMaxTries;
    final Logger logger = new DefaultLogger(Logger.Level.INFO, System.err);
    final OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(TIMEOUT)
            .readTimeout(TIMEOUT)
            .callTimeout(TIMEOUT)
            .build();

    public GalileoProfileExporter(Ocp.Resource resource, int ingestMaxTries) {
        this.resource = resource;
        this.ingestMaxTries = ingestMaxTries;
    }

    @Override
    public void export(Snapshot snapshot) {
        final HttpUrl url = HttpUrl.parse(ENDPOINT);
        logger.log(Logger.Level.INFO, "Upload profile. %s %s JFR: %s",
                snapshot.started.toString(), snapshot.ended.toString(), snapshot.data.length);
        byte[] reqBody = constructReqBody(snapshot);
        byte[] compressedData = new byte[0];
        try {
            compressedData = Snappy.compress(reqBody);
        } catch (IOException e) {
            logger.log(Logger.Level.ERROR, "Error compress snapshot.");
        }
        MediaType type = MediaType.parse("application/octet-stream");
        RequestBody jfrBody = RequestBody.create(compressedData, type);
        Request.Builder request = new Request.Builder()
                .post(jfrBody)
                .url(url);
        request.header("language", "java");

        try (Response response = client.newCall(request.build()).execute()) {
            int status = response.code();
            if (status >= 400) {
                ResponseBody body = response.body();
                final String responseBody;
                if (body == null) {
                    responseBody = "";
                } else {
                    responseBody = body.string();
                }
                logger.log(Logger.Level.ERROR, "Error uploading snapshot: %s %s", status, responseBody);
            }
            if (status == 200) {
                logger.log(Logger.Level.INFO, "Success upload jfr");
            }
        } catch (final IOException e) {
            logger.log(Logger.Level.ERROR, "Error uploading snapshot: %s", e.getMessage());
        }
    }

    private byte[] constructReqBody(Snapshot snapshot) {
        Otp.Profile.Builder profile = Otp.Profile.newBuilder()
                .setName("jfr")
                .setType("cpu")
                .setData(ByteString.copyFrom(snapshot.data));
        Otp.ProfilesBatch profilesBatch = Otp.ProfilesBatch.newBuilder()
                .setSequence(1)
                .setStart(snapshot.started.toEpochMilli() / 1000)
                .setEnd(snapshot.ended.toEpochMilli() / 1000)
                .setResource(this.resource)
                .addProfiles(profile)
                .build();
        return profilesBatch.toByteArray();
    }

}

When I opened the agent report, I found that the memory was constantly rising, and I suspected there was a memory leak situation
image

Is there anyone who has encountered similar problems with me, or is there a problem with where I wrote it? Thanks

Ngôn ngữ chính
Java
Star
125
Fork
48
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của grafana/pyroscope-java

Tất cả issue của grafana/pyroscope-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.