Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Perl Memory problem ...

by Sascha2018 (Acolyte)
on May 13, 2020 at 17:17 UTC ( [id://11116761]=note: print w/replies, xml ) Need Help??


in reply to Perl Memory problem ...

Hello. Thanks for the replies. Here is a little bit of my perl script i wrote. The problem is: At start time it uses 10MB Memory. And if a user writes a message ( SENDMESSAGE ) , it needs for every message ( 300 KB of memory ). Now ... how can i fix the problem?
use feature 'state'; use Time::HiRes; require "config.cfg"; require "Subs.pl"; require "format.pl"; require "server/mainprogram_subs.pl"; require "ConnectDB.pl"; require "loadconfig.pl"; require "$config{language}.lng"; require 5.002; use IO::Socket::SSL 'inet4'; $IO::Socket::SSL::DEBUG = 3; use IO::Select; use Time::HiRes; use HTML::Template; use Text::Wrap; use Fcntl ':flock'; use strict; no strict 'refs';
later in my program:
if($buffer =~ /^SENDMESSAGE$digest\|(.*?)$/){ my $what = $1; my($room,$touser,$kind,$message,$fromuser)= +split /\|/, $what; my $myuser = $fromuser; my $update_sock = getCurrentIdent($myuser); if( SockExists($update_sock) ) { $clients{$update_sock}->{lastsrvpost} = ti +me; } if($touser eq "" && $room ne "" && $kind ne +"PRVMESSAGE") { sendToSocket($message, { toroom => $room, kind => + $kind, fromuser => $myuser } ); }elsif($touser ne "" && $room eq "" && $kind + ne "PRVMESSAGE" ) { sendToSocket($message,{ fromuser => $myuser, tou +ser => $touser, kind => $kind } ); }elsif($touser eq "" && $room eq "" && $kind + ne "PRVMESSAGE") { sendToSocket($message, {}); } next;
and the sendToSocket routine is the following:
sub sendToSocket { my( $data, $params ) = @_; if( $data eq "" ) { return 0; } if( $params->{toroom} ne "" && $params->{touser} eq "" ) { foreach my $ident( keys %clients ) { our $nick = $clients{$ident}->{nick}; if( isInIgnorelist($nick, $params->{fromuser}) && $co +nfig{ignore_modus}{$params->{kind}}==1) { }else{ my %info = loadMemberInfo($nick); if( lc $params->{toroom} eq lc $info{room}) { my $fh = $clients{$ident}->{sock}; if( defined $fh ){ my $msg = createFilter($ident, $data); $fh->syswrite($msg . "\n"); undef $fh; undef $msg; undef %info; undef $nick; } } } } }elsif( $params->{toroom} eq "" && $params->{touser} ne "" ) { my $user = $params->{touser}; my $sock = getCurrentSocket($user); my $sn= $sock->{sockname}; my $socket = $sock->{socket}; my $ident = getCurrentIdent($user); if( isInIgnorelist($clients{$sn}->{nick}, $params->{from +user}) && $config{ignore_modus}{$params->{kind}}==1 ) { }else{ if( defined $socket ){ $msg = createFilter($ident, $data); $socket->syswrite($msg . "\n"); undef $msg; undef $ident; undef $sock; } } }elsif( $params->{touser} eq "" && $params->{toroom} eq "" ) { foreach my $ident( keys %clients ) { my $sock = $clients{$ident}->{sock}; $msg = createFilter($ident, $data); if( defined $sock ){ $sock->syswrite($msg . "\n"); } undef $msg; undef $sock; } } }
But if i use undef, nothing happens. It still uses the memory :( Hope you can help. Thanks Regards Sascha

Replies are listed 'Best First'.
Re^2: Perl Memory problem ...
by Corion (Patriarch) on May 13, 2020 at 17:35 UTC

    Most likely, your problem lies somewhere else as here you clean out the variables you create locally.

    Take a look at Devel::Cycle and/or Devel::LeakTrace and Devel::FindRef to see where your program is collecting memory. Ideally, you can eliminate all server/client interaction and use a faked client message in a loop to reproduce the problem.

    You might want to change the coding style from

    our $nick = $clients{$ident}->{nick};

    ... to

    my $nick = $clients{$ident}->{nick};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116761]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found