简体   繁体   English

im4java中的进程池

[英]Process Pooling in im4java

Guys am using imagemagick library for image processing in my project(java). 伙计们正在使用imagemagick库在我的项目(java)中进行图像处理。 When multiple requests hit the server, it responds very slowly. 当多个请求到达服务器时,它的响应速度非常慢。 Now, multiple convert commands ( executes as an individual process ) are executed simultaneously and to avoid delay am thinking of process pooling in im4java. 现在,同时执行多个convert命令(作为一个单独的进程执行),并避免在im4java中考虑process pooling ,从而避免了延迟。 Following alternatives would be of any help ? 以下替代方案会有所帮助吗? :

  • Process Pooling in im4java - Is there any way to achieve solely in im4java(should i use gm4java wrapper, i guess it supports process pooling - BUT, it has few limitations like no use of buffered images)? im4java中的进程池 -是否有任何方法可以仅在im4java中实现(我应该使用gm4java包装器,我猜它支持进程池-但是,它有一些限制,例如不使用缓冲图像)?
  • Dedicated Server - Using a dedicated server just for image processing (the least i want). 专用服务器 -使用仅用于图像处理的专用服务器(至少我需要)。

Is there any OTHER method should i go for ? 我还应该使用其他方法吗? Thanks for help in advance ! 预先感谢您的帮助!

Actually, our team went through exactly the same requirement and hence we created gm4java. 实际上,我们的团队经历了完全相同的要求,因此我们创建了gm4java。 It does exactly what you are looking for. 它确实满足您的需求。 As to the support for BufferedImage, we already support using BufferedImage as input in the latest release . 关于对BufferedImage的支持,我们已经支持在最新版本中使用BufferedImage作为输入。 Using BufferedImage as output is still not supported but you can workaround it easily. 仍然不支持使用BufferedImage作为输出,但是您可以轻松解决它。

The workaround is to let GM write the image to the RAM disk (in many Linux distributions, you get RAM disk for free, for Windows there are various solutions available). 解决方法是让GM将映像写入RAM磁盘(在许多Linux发行版中,您可以免费获得RAM磁盘,对于Windows,有各种可用的解决方案)。 All you need to do now is to have your Java code reads the converted image from the RAM disk. 您现在要做的就是让您的Java代码从RAM磁盘读取转换后的图像。 The little overhead (if any) is indifference comparing to the huge overhead of starting a new process each time. 与每次启动一个新进程的巨大开销相比,很少的开销(如果有的话)是无差别的。

Even directly comparing with RAM disk approach to BufferedImage, the size of BufferedImage is often 10 times larger than a byte array of a JPG image file. 即使直接与RAM磁盘方法比较BufferedImage,BufferedImage的大小通常也比JPG图像文件的字节数组大10倍。 So if all you need is to serve images instead of doing additional processing in Java, the RAM disk approach is indeed faster also uses less memory. 因此,如果您只需要提供图像而不是用Java进行其他处理,那么RAM磁盘方法的确确实更快,而且占用的内存更少。

More about current BufferedImage implementation in im4java. 有关im4java中当前BufferedImage实现的更多信息。 When using it as input, it was simply written to a tmp file, which is very slow. 当使用它作为输入时,它只是写到一个tmp文件中,这非常慢。 When using it as output, it utilizes stdin/stdout stream operations, which is faster than tmp file but still not optimal. 当将其用作输出时,它利用stdin / stdout流操作,该操作比tmp文件快,但仍不是最佳选择。 The best would be to use named pipe with Java NIO implementation. 最好的方法是在Java NIO实现中使用命名管道。 But that will require quite a bit of, most like API breaking, changes in im4java. 但这将需要对im4java进行大量的更改(最像API中断)。

Lastly, I would NOT consider gm4java a wrapper of im4java, the core of gm4java runs by itself and gives you the capability of sending massive concurrent commands to GM and to return the output of GM back to you. 最后,我不会将gm4java视为im4java的包装,gm4java的核心本身运行,并为您提供了向GM发送大量并发命令并将GM的输出返回给您的功能。 Commands are just a list of strings, so if you know how to write GM commands, you don't need im4java to use gm4java. 命令只是字符串列表,因此,如果您知道如何编写GM命令,则不需要im4java即可使用gm4java。 That is actually how we used in an application that demands raw performance. 实际上,这就是我们在需要原始性能的应用程序中使用的方式。 im4java give you a convenience way (with some overhead) to construct the GM command and to parse the GM output. im4java为您提供了一种方便的方式(有一些开销)来构造GM命令并解析GM输出。 GMBatchCommand class in gm4java serves a bridge between im4java and gm4java. gm4java中的GMBatchCommand类在im4java和gm4java之间架起了一座桥梁。 It let you use that convenience from im4java to construct the commands, then use gm4java engine to execute the command. 它使您可以利用im4java的便利性来构建命令,然后使用gm4java引擎执行命令。 The gm4java engine uses a completely different mechanism than im4java to manage and to communicate with GM. gm4java引擎使用与im4java完全不同的机制来管理和与GM通信。 And that's the reason why it is so fast. 这就是为什么它这么快的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM