When perl function executes first time, it is too slowly, but if
execute perl function(not function which executed first time) again it
runs in 1000 times faster. Why ? how can i optimize it ?
Configure shared_preload_libraries = '$libdir/plperl' or
local_preload_libraries = '$libdir/plugins/plperl' does not help;
Reproduce code:
-- First of all, creating functions
CREATE OR REPLACE FUNCTION "perl_test_speed" () RETURNS
"pg_catalog"."void" AS $body$;$body$ LANGUAGE 'plperl' VOLATILE CALLED
ON NULL INPUT SECURITY INVOKER;
CREATE OR REPLACE FUNCTION "perl_test_speed_two" () RETURNS
"pg_catalog"."void" AS $body$;$body$ LANGUAGE 'plperl' VOLATILE CALLED
ON NULL INPUT SECURITY INVOKER;
-- Reopen connection(THIS IS IMPORTANT STEP!)
-- Execute:
EXPLAIN ANALYZE SELECT perl_test_speed();
-- Result:Result (cost=0.00..0.26 rows=1 width=0) (actual
time=149.994..149.999 rows=1 loops=1)Total runtime: 150.363 ms -- WTF?
-- Other calls in this connection:
EXPLAIN ANALYZE SELECT perl_test_speed();
-- Result:Result (cost=0.00..0.26 rows=1 width=0) (actual time=0.121..0.122
rows=1 loops=1)Total runtime: 0.176 ms
-- Reopen connection(THIS IS IMPORTANT STEP!)
EXPLAIN ANALYZE SELECT perl_test_speed_two();
----------------------------------------------------------------------------------------Result (cost=0.00..0.26 rows=1
width=0)(actual
time=173.713..173.716 rows=1 loops=1)Total runtime: 174.073 ms -- WTF ?
EXPLAIN ANALYZE SELECT perl_test_speed();
------------------------------------------------------------------------------------Result (cost=0.00..0.26 rows=1
width=0)(actual time=0.973..0.975
rows=1 loops=1)Total runtime: 1.035 ms
EXPLAIN ANALYZE SELECT perl_test_speed();
------------------------------------------------------------------------------------Result (cost=0.00..0.26 rows=1
width=0)(actual time=0.122..0.123
rows=1 loops=1)Total runtime: 0.171 ms
-- END;
How can i make it run faster, after every reconnect ?
Thanks!
PS. Sorry for my English.