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

Memory leak when executing a lot of different queries and StatementTimeout > 0 #8085

Closed
pavel-zotov opened this issue Apr 17, 2024 · 2 comments

Comments

@pavel-zotov
Copy link

Make firebird.conf empty and then add into it the single line:

StatementTimeout = 7200

Restart FB service.
Run some tool that can show memory consumprion per process, e.g. ProcessExplorer (on Windows).
Try following example (it will run infinitely so one need to cancel it via Ctrl-Break):

set list on;
set bail on;
shell del e:\temp\tmp4test.fdb 2>nul;
create database 'localhost:e:\temp\tmp4test.fdb' user sysdba password 'masterkey';

select *
from rdb$config where rdb$config_name = 'StatementTimeout';

set term ^;
execute block as
    declare i int = 0;
    declare res int;
begin
    while (1 = 1) do
    begin
        -- execute statement ( 'select rand() from rdb$database' ) -- [1] constant
        -- execute statement ( 'select ' || 1 || ' from rdb$database' ) -- [2] constant
        execute statement ( 'select ' || rand() || ' from rdb$database' ) -- [3] growth
        into res;
        i = i + 1;
    end
end
^
set term ;^

Watch into details for firebird process in ProcessExplorer (swich to 'performance graph').
You will see somth like:
image

No such problem if we comment out parameter 'StatementTimeout' in the firebird.conf.

Checked on 6.0.0.315.

PS.
I was unable to determine the exact value of the threshold of the number of unique expressions, after exceeding which memory growth begins. I checked MOD(i, N) function (instead of rand()) where N had different values.
It seemed firstly that N is ~16, but then i get results with constant memory consumption for greater values (i.e. for N = 17, 33, 67, 129 etc).

@hvlad hvlad self-assigned this Apr 17, 2024
@hvlad hvlad changed the title Presense of StatementTimeout > 0 causes to memory growth in case of loop with unique expressions runing via ES Memory leak when executing a lot of different queries and StatementTimeout > 0 Apr 17, 2024
hvlad added a commit that referenced this issue Apr 17, 2024
hvlad added a commit that referenced this issue Apr 17, 2024
hvlad added a commit that referenced this issue Apr 17, 2024
@hvlad
Copy link
Member

hvlad commented Apr 17, 2024

I was unable to determine the exact value of the threshold of the number of unique expressions, after exceeding which memory growth begins. I checked MOD(i, N) function (instead of rand()) where N had different values.
It seemed firstly that N is ~16, but then i get results with constant memory consumption for greater values (i.e. for N = 17, 33, 67, 129 etc).

16 is the number of statements cached by external connection. I.e. statements was reused and no memory leak could be detected, while it actually there - near 40 bytes per statement.

@hvlad hvlad closed this as completed Apr 17, 2024
@hvlad
Copy link
Member

hvlad commented Apr 17, 2024

BTW, you don't have to change firebird.conf to reproduce it.
It is enough to execute SET STATEMENT TIMEOUT <N> before the EXECUTE BLOCK, with N > 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment