[Kamailio-Users] perl module, "pv_sprintf: Memory exhausted!"

Daniel-Constantin Mierla miconda at gmail.com
Mon May 18 15:39:49 CEST 2009


Hello,

On 05/18/2009 04:24 PM, Christian Koch wrote:
> Hi all,
>
> we're using kamailio 1.5.1 with modules htable and perl to generate 
> CDRs. Using htable we save some variables which are dumped to file using 
> the perl module at the end of the call.
> We did a small stress test with 5 calls in parallel (each call about 20 
> seconds) and we got after about 6 hours the following error:
>
>     ERROR:core:pv_sprintf: pv_sprintf: Memory exhausted!
>   
this is system memory error. Has nothing to do with pkg memory used by 
Kamailio. Seems that perl module allocates some memory and forgets to 
free it. Do you see other errors in your syslog?

One memleak I could spot is that the allocated buffer to print the 
output in pv_sprintf is not freed if the formatted string is bad. Then I 
see that the output buffer is duplicated with strdup and it is freed. So 
seems there are some system memory leaks in perl module, indeed.
> No CDRs were written anymore, the perl method was not called. Everything 
> else seems to run fine.
>   
Yes, because the problem was with system memory, while kamailio uses 
internally pkg.

> After stopping the stress test doing one simple call with a softphone 
> worked and a CDR had been written (without restarting kamailio!). 
> Perhaps the perl script is buggy?
>   
I have no much experience with perl to state that.

> Any ideas how to fix this are greatly appreciated. We don't think 
> extending the PKG_MEM_POOL_SIZE will solve the problem. This is 
> currently 4MB and should be enough for 5 concurrent calls!?!
>   
pkg is more than enough.


Cheers,
Daniel

> Thanks,
> Christian Koch
>
> The perl script:
>
>
> use OpenSER;
> use OpenSER::Constants;
> use IO::Socket;
>
> sub write_cdr {
>         my $m = shift;
>
>         #my $v = $m->getVersion();
>         #my $t = $m->getType();
>
>         my $index = $m->pseudoVar("\$ci");
>
>         my $endTimeStamp = $m->pseudoVar("\$Ts");
>         my $startTimeStamp = $endTimeStamp - 
> $m->pseudoVar("\$DLG_lifetime");
>
>         
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($startTimeStamp);
>         my $startTime = sprintf("%02d.%02d.%4d;%02d:%02d:%02d", $mday, 
> $mon+1, $year+1900, $hour, $min, $sec);
>         my $fileDate = sprintf("%02d%02d%02d", $mday, $mon+1, $year%100);
>
>         
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($endTimeStamp);
>         my $endTime = sprintf("%02d.%02d.%4d;%02d:%02d:%02d", $mday, 
> $mon+1, $year+1900, $hour, $min, $sec);
>
>         
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($m->pseudoVar("\$sht(a=>".$index."::invtrytime)"));
>         my $InvTryingTime = sprintf("%02d.%02d.%4d;%02d:%02d:%02d", 
> $mday, $mon+1, $year+1900, $hour, $min, $sec);
>
>         $ReplyReason=$m->pseudoVar("\$rr");
>         $ReplyReason=~ s/;/_/g;
>
>         $FromDisplayName = 
> $m->pseudoVar("\$sht(a=>".$index."::fromdplname)");
>         $FromDisplayName=~ s/;/_/g;
>
>         $ToUri = $m->pseudoVar("\$sht(a=>".$index."::touri)");
>         $ToUri=~s/;/_/g;
>
>         $FromUri = $m->pseudoVar("\$sht(a=>".$index."::fromuri)");
>         $FromUri=~s/;/_/g;
>
>         $UserAgent = $m->pseudoVar("\$sht(a=>".$index."::useragent)");
>         $UserAgent=~s/;/_/g;
>
>         my $CDR = $startTime.";"; # 1 + 2
>         $CDR .= $endTime.";";     # 3 + 4
>         $CDR .= $m->pseudoVar("\$DLG_lifetime").";"; # 5
>         $CDR .= $index.";"; #6 CallID
>         $CDR .= $m->pseudoVar("\$sht(a=>".$index."::srcip)").";";   #   
> source-IP of INVITE
>         $CDR .= $m->pseudoVar("\$si").";";   #   source-IP of BYE/CANCEL
>         $CDR .= $FromDisplayName.";"; #  from display-name INVITE
>         $CDR .= $InvTryingTime.";";   # Alerting time
>         $CDR .= ($startTimeStamp - 
> $m->pseudoVar("\$sht(a=>".$index."::invtrytime)")).";"; #Alerting period
>         $CDR .= $m->pseudoVar("\$DLG_count").";";  # current amount of calls
>         $CDR .= $ToUri.";"; # ToUri from Invite
>         $CDR .= $FromUri.";"; # FromUri from Invite
>         $CDR .= $UserAgent.";"; # UserAgent from Invite
>         $CDR .= $m->pseudoVar("\$rm").";"; # Method (INVITE,BYE,CANCEL)
>         $CDR .= $m->pseudoVar("\$rs").";"; # SIP reply status  
>         $CDR .= $ReplyReason.";"; #SIP Reply reason
>
>
>         open(MYOUTFILE, 
> ">>/home/sys/log/kamailio".$fileDate.".cdr.".$m->pseudoVar("\$pp"));
>         print MYOUTFILE $CDR."\n";
>         close(MYOUTFILE);
>
>         #delete(%sourceIp->{$index});  
>         #delete(%fromDisplayName->{$index}); 
>         #delete(%InviteTryingTimestamp->{$index}); 
>         #delete(%ToUri->{$index}); 
>         #delete(%FromUri->{$index}); 
>         #delete(%UserAgent->{$index});
>
>
>         return 1;
> }
>
> 1;
>
> _______________________________________________
> Kamailio (OpenSER) - Users mailing list
> Users at lists.kamailio.org
> http://lists.kamailio.org/cgi-bin/mailman/listinfo/users
> http://lists.openser-project.org/cgi-bin/mailman/listinfo/users
>
>   

-- 
Daniel-Constantin Mierla
http://www.asipto.com/




More information about the Users mailing list