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

The memory will not be released, even if collectgarbage("collect") is executed #157

Open
lzle opened this issue Jun 20, 2023 · 1 comment

Comments

@lzle
Copy link
Contributor

lzle commented Jun 20, 2023

The memory will not be released, even if collectgarbage("collect") is executed. thanks!

location / {
    content_by_lua '
        local kafka_producer = require("resty.kafka.producer")
    
        local brokers = {
            { host = "10.104.67.26", port = 9092 },
            { host = "10.104.67.35", port = 9092 },
            { host = "10.104.67.47", port = 9092 }
        }
    
        local producer_config = {
                        producer_type   = "async",
                        max_retry       = 1,
                        batch_num       = 1000,
                        max_buffering   = 1024000,
                        }
    
        local producer = kafka_producer:new(brokers, producer_config, nil)
    
        local message = string.rep('a',  512)
    
        for i = 1, 1024000 do
            local ok, err = producer:send('original-kernel-log', nil, message .. i)
            if not ok then
               ngx.say("add err:", err)
            end
        end
    
        while true do
            if producer.ringbuffer.num == 0 then
                ngx.log(ngx.INFO, "collectgarbage")
                collectgarbage("collect")
                ngx.sleep(30)
            end
            ngx.sleep(1)
        end
    
        ngx.say("ok")
    ';
}
@lzle
Copy link
Contributor Author

lzle commented Jun 27, 2023

I found the problem, it was caused by the table, next is demo, the memory will not release.

local table_new = require("table.new")
function _M.rewrite()
    local queue = table_new(10240000, 0)

    local message = string.rep('a',  1024)
    for i = 1, 10240000 do
        queue[i] = message .. i
    end

    for i = 1, 10240000 do
        queue[i] = nil
    end

    ngx.log(ngx.INFO, 'collectgarbage')
    collectgarbage("collect")

    front_resp.quit_normal()
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant