锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 英语翻译 / Apache / Perl内存不足和DPERL_EMERGENCY_SBRK解决方法
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。需要全文内容也请联系孙老师。

Perl内存不足和DPERL_EMERGENCY_SBRK解决方法

If something goes really wrong with your code, Perl may die with an "Out of memory!" message and/or "Callback called exit". Common causes of this are never-ending loops, deep recursion, or calling an undefined subroutine.

如果出现错误代码,Perl会因为”内存不足!”消息和/或“被调用回调退出”而退出。常见的原因是无限循环,深度递归,或调用一个未定义子例程。

If you are using perl 5.005 or later, and perl is compiled to use it’s own malloc rutines, you can trap out of memory errors by setting aside an extra memory pool in the special variable $^M. By default perl uses the operating system malloc for many popular systems, so unless you build perl with ’usemymalloc=y’ you probably wont be able to use $^M. Run:

如果您正在使用perl 5.005或更高版本,并且perl编译使用它自己的分配内存的程序。您可以通过在特殊变量$^ M.设置额外的内存器跟踪内存不足的错误。在默认情况下perl使用的malloc支持许多流行操作系统,所以除非你用“usemymalloc = y”编译perl,你可能习惯于使用$^M。运行:

% perl -V:usemymalloc

if your mod_perl was compiled against perl which uses internal malloc() the answer will be ’y’. 如果你编译的mod_perl对应perl使用了内部malloc,答案是“Y”。

Here is an explanation of $^M from the perlvar manpage: 下面是$^M来自perlvar手册页的解释:

By default, running out of memory is an untrap- pable, fatal error. 默认情况下,内存消耗完是不可以捕获的致命错误。

However, if suitably built, Perl can use the contents of $^M as an emergency memory pool after die()ing. 然而,如果合适地编译,Perl能使用$^M,在消失后把它当做急救内存池。

Suppose that your Perl were compiled with -DPERL_EMERGENCY_SBRK and used Perl’s malloc. Then 假定你Perl编译选项里有-DPERL_EMERGENCY_SBRK,且使用了Perl的malloc

$^M = ’a’ x (1 << 16);

would allocate a 64K buffer for use in an emer- gency. See the INSTALL file in the Perl distribu- tion for information on how to enable this option. To discourage casual use of this advanced feature, there is no English long name for this variable. 会分配64K缓冲来救急用。检查INSTALL安装文件来学习如何打开这个选项。为了不鼓励使用这个高级特性,这个变量没有英文长名称。

If your perl installation supports $^M and you add ’use Apache::Debug level => 4;’ to your Perl script, it will allocate the $^M emergency pool and the $SIG{__DIE__} handler will call Carp::confess, giving you a stack trace which should reveal where the problem is. See the Apache::Resource module for ways to control httpd processes.

如果你的perl安装支持 $^M 那么你可以添加“use Apache::Debug level => 4;,“给你的Perl脚本,它将分配$^M 应急池和$SIG{__DIE__} 处理程序来调用 Carp::confess,给你一个堆栈跟踪能够揭示问题在哪里。请阅读Apache::资源模块的方法来控制httpd进程。

Note that Perl 5.005 and later have PERL_EMERGENCY_SBRK turned on by default. Another trick is to have a startup script initialize Carp::confess, like so: 注意Perl 5.005和更高版本有PERL_EMERGENCY_SBRK默认启动。另一个技巧是有一个启动脚本初始化Carp::confess,,像这样:

use Carp ();

eval { Carp::confess("init") };

this way, when the real problem happens, Carp::confess doesn’t eat memory in the emergency pool ($^M). 这样,当真正的问题发生时,Carp::confess在($^M)应急池中 不占用内存。

Some other mod_perl users have reported that this works well for them: 其他一些mod_perl用户报道,这适用于他们:

# Allocate 64K as an emergency memory pool for use in out of

# memory situation

$^M = 0x00 x 65536;

# Little trick to initialize this routine here so that in the case

# of OOM, compiling this routine doesn’t eat memory from the

# emergency memory pool $^M

use CGI::Carp ();

eval { CGI::Carp::confess(’init’) };

# Importing CGI::Carp sets $main::SIG{__DIE__} = \&CGI::Carp::die;

# Override that to additionally give a stack backtrace

$main::SIG{__DIE__} = \&CGI::Carp::confess;

Discussion of $^M has come up on PerlMonks, and there is speculation that $^M is a forgotten feature that’s not well supported. See http://perlmonks.org/index.pl?node_id=287850 for more information. $^M的讨论在PerlMonks开始,有猜测$^M是一个被遗忘的特性且支持的不好。参见http://perlmonks.org/index.pl?node_id = 287850的更多信息。

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内