[英]Best way to run a Perl script from weblogic Java EE application
I currently work in a Weblogic Java EE project, where from time to time the application executes a Perl script to do some batch jobs. 我目前在Weblogic Java EE项目中工作,其中应用程序不时执行Perl脚本来执行一些批处理作业。 In the application the script is getting invoked as 在应用程序中,脚本被调用为
Process p = Runtime.getRuntime().exec(cmdString);
Though it is a dangerous way to run, but it was working properly until we had a requirement to execute the script synchronously under a for loop. 虽然这是一种危险的运行方式,但它正常工作,直到我们要求在for循环下同步执行脚本。 After a couple of run we are getting java.io.IOException: Not enough space
as probably OS is running out of virtual memory while exec-ing under a for loop. 经过几次运行后,我们得到java.io.IOException: Not enough space
因为在执行for循环时OS可能正在耗尽虚拟内存。 As a result we are not able to run the script at all in the server. 因此,我们无法在服务器中运行该脚本。
I am desperately looking for a safer and better way to run the Perl script, where we don't need to fork the parent process, or at-least not to eat-up all swap space! 我正在拼命寻找一种更安全,更好的方式来运行Perl脚本,我们不需要分叉父进程,或者至少不要占用所有交换空间!
The spec is as follows: 规格如下:
Appserver - Weblogic 9.52
JDK - 1.5
OS - SunOS 5.10
Sun-Fire-T200
I've had something similar on a couple of occasions. 我有几次类似的东西。 Since the child process is a fork of the (very large parent it can see all of it shares all it's memory (using copy on write). What i discovered was that the kernel needs to be able to ensure that it could copy all of the memory pages before forking the child, on a 32bit OS you run out of virtual head run really fast. 由于子进程是一个分支(非常大的父进程,它可以看到所有它共享所有内存(使用写入时的副本)。我发现内核需要能够确保它可以复制所有的分叉之前的内存页面,在32位操作系统上,你的虚拟头运行速度非常快。
Possible solutions: 可能的解决方案:
创建一个perl-server,它通过网络读取perl脚本并逐个执行。
If you want to keep your code unchanged and have enough disk free space, you can just add a sufficiently large swap area to your OS. 如果要保持代码不变并且有足够的磁盘可用空间,可以在操作系统中添加足够大的交换区域。
Assuming you need 10 GB, here is how you do it with UFS: 假设您需要10 GB,以下是使用UFS的方法:
mkfile 10g /export/home/10g-swap
swap -a /export/home/10g-swap
echo "/export/home/10g-swap - - swap - no -" >> /etc/vfstab
If you use ZFS, that would be: 如果您使用ZFS,那将是:
zfs create -V 10gb rpool/swap1
swap -a /dev/zvol/dsk/rpool/swap1
Don't worry about that large a swap, this won't have any performance impact as the swap will only be used for virtual memory reservation, not pagination. 不要担心大的交换,这不会对性能产生任何影响,因为交换只会用于虚拟内存预留,而不是分页。
Otherwise, as already suggested in previous replies, one way to avoid the virtual memory issue you experience would be to use a helper program, ie a small service that your contact through a network socket (or a higher level protocol like ssh) and that executes the perl script "remotely". 否则,正如之前的回复中已经建议的那样,避免您遇到的虚拟内存问题的一种方法是使用帮助程序,即通过网络套接字(或更高级别的协议,如ssh)联系并执行的小型服务perl脚本“远程”。
Note that the issue has nothing to do with a 32-bit or 64-bit JVM, it is just Solaris doesn't overcommit memory and this is by design. 请注意,该问题与32位或64位JVM无关,只是Solaris不会过度使用内存,这是设计使然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.