久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='wyusf'></small><noframes id='wyusf'>

    <tfoot id='wyusf'></tfoot>

      1. <i id='wyusf'><tr id='wyusf'><dt id='wyusf'><q id='wyusf'><span id='wyusf'><b id='wyusf'><form id='wyusf'><ins id='wyusf'></ins><ul id='wyusf'></ul><sub id='wyusf'></sub></form><legend id='wyusf'></legend><bdo id='wyusf'><pre id='wyusf'><center id='wyusf'></center></pre></bdo></b><th id='wyusf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wyusf'><tfoot id='wyusf'></tfoot><dl id='wyusf'><fieldset id='wyusf'></fieldset></dl></div>
        <legend id='wyusf'><style id='wyusf'><dir id='wyusf'><q id='wyusf'></q></dir></style></legend>
        • <bdo id='wyusf'></bdo><ul id='wyusf'></ul>

        使用 redis/php-resque 優化并發 ImageMagick 請求

        Optimising concurrent ImageMagick Requests using redis/php-resque(使用 redis/php-resque 優化并發 ImageMagick 請求)
        <legend id='RNvDA'><style id='RNvDA'><dir id='RNvDA'><q id='RNvDA'></q></dir></style></legend>

        <small id='RNvDA'></small><noframes id='RNvDA'>

        1. <i id='RNvDA'><tr id='RNvDA'><dt id='RNvDA'><q id='RNvDA'><span id='RNvDA'><b id='RNvDA'><form id='RNvDA'><ins id='RNvDA'></ins><ul id='RNvDA'></ul><sub id='RNvDA'></sub></form><legend id='RNvDA'></legend><bdo id='RNvDA'><pre id='RNvDA'><center id='RNvDA'></center></pre></bdo></b><th id='RNvDA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RNvDA'><tfoot id='RNvDA'></tfoot><dl id='RNvDA'><fieldset id='RNvDA'></fieldset></dl></div>
            <bdo id='RNvDA'></bdo><ul id='RNvDA'></ul>
              <tfoot id='RNvDA'></tfoot>
                  <tbody id='RNvDA'></tbody>
                • 本文介紹了使用 redis/php-resque 優化并發 ImageMagick 請求的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在一個使用 ImageMagick 生成圖像的網站上工作.該站點每分鐘將收到數百個請求,使用 ImageMagick 執行此操作會導致站點崩潰.

                  I am working on a site that uses ImageMagick to generate images. The site will get hundreds of request every minute and using ImageMagick to do this causes the site to crash.

                  所以我們實現了 Redis 和 Php-resque 來在單獨的服務器上在后臺生成 ImageMagick,這樣它就不會使我們的主要服務器崩潰.問題是完成圖像仍然需要很長時間.用戶可能希望等待最多 2-3 分鐘的圖像請求,因為服務器正忙于處理這些圖像.

                  So we implemented Redis and Php-resque to do the ImageMagick generating in the background on a seperate server so that it doesn't crash our main one. The problem is that it's still taking a very long time to get images done. A user might expect to wait up to 2-3 minutes for an image request because the server is so busy processing these images.

                  我不知道該給你什么信息,但我更多的是在尋求建議.我認為如果我們可以減少 ImageMagick 請求的初始處理時間,那么顯然這將有助于加快我們可以處理的圖像數量.

                  I am not sure what information to give you, but I'm more looking for advice. I think if we can cut down the initial process time for the ImageMagick request, then obviously this will help speed up the amount of images we can process.

                  以下是我們使用的 ImageMagick 腳本示例:

                  Below is a sample of the ImageMagick script that we use:

                  convert -size 600x400 xc:none ( ".$path."assets/images/bases/base_image_69509021433289153_8_0.png -fill rgb(255,15,127) -colorize 100% ) -composite ( ".$path."assets/images/bases/eye_image_60444011438514404_8_0.png -fill rgb(15,107,255) -colorize 100% ) -composite ( ".$path."assets/images/markings/marking_clan_8_marking_10_1433289499.png -fill rgb(255,79,79) -colorize 100% ) -composite ( ".$path."assets/images/bases/shading_image_893252771433289153_8_0.png -fill rgb(135,159,255) -colorize 100% ) -compose Multiply -composite ( ".$path."assets/images/highlight_image_629750231433289153_8_0.png -fill rgb(27,35,36) -colorize 100% ) -compose Overlay -composite ( ".$path."assets/images/lineart_image_433715161433289153_8_0.png -fill rgb(0,0,0) -colorize 100% ) -compose Over -composite ".$path."assets/generated/queue/tempt_preview_27992_userid_0_".$filename."_file.png
                  

                  我的理論是,這需要很長時間的原因是對圖像進行著色的過程.有沒有辦法優化這個過程?

                  My theory is that the reason this takes quite a long time is due to the process of colouring the images. Is there a way to optimise this process at all?

                  如果您有處理大量 imagemagick 進程的經驗,或者可以看到一些非常簡單的方法來優化我們的請求,我會非常感激.

                  Anyone who has some experience with handling heavy loads of imagemagick processes or can see some glaringly easy ways to optimise our requests, I'd be very greatful.

                  謝謝:)

                  推薦答案

                  你的命令實際上可以歸結為:

                  Your command actually boils down to this:

                  convert -size 600x400 xc:none                                 
                      ( 1.png -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 2.png -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 3.png -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 4.png -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 5.png -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 6.png -fill rgb(x,y,z) -colorize 100% ) -composite  
                      result.png
                  

                  我的想法如下:

                  第 1 點:

                  在空白畫布上的第一個 -composite 似乎毫無意義 - 大概 1.png 是具有透明度的 600x400 PNG,因此您的第一行可以避免合成操作并保存16% 的處理時間改為:

                  The first -composite onto a blank canvas seems pointless - presumably 1.png is a 600x400 PNG with transparency, so your first line can avoid the compositing operation and save 16% of the processing time by changing to:

                  convert -background none 1.png -fill ... -colorize 100% 
                     ( 2.png ..
                     ( 3.png ...
                  

                  第 2 點

                  我將與您的命令等效的命令放入循環中并進行了 100 次迭代,耗時 15 秒.然后我將您對 PNG 文件的所有讀取更改為對 MPC 文件或 Magick Pixel Cache 文件的讀取.這將處理時間縮短到不到 10 秒,即減少了 33%.Magic Pixel Cache 只是一個預解壓、預解碼的文件,可以直接讀入內存而無需任何 CPU 工作.您可以在目錄更改時預先創建它們并將它們與 PNG 文件一起存儲.做一個你做的

                  I put the equivalent of your command into a loop and did 100 iterations and it takes 15 seconds. I then changed all your reads of PNG files into reads of MPC files - or Magick Pixel Cache files. That reduced the processing time to just under 10 seconds, i.e. by 33%. A Magic Pixel Cache is just a pre-decompressed, pre-decoded file that can be read directly into memory without any CPU effort. You could pre-create them whenever your catalogue changes and store them alongside the PNG files. To make one you do

                  convert image.png image.mpc
                  

                  你會得到image.mpcimage.cache.然后您只需將代碼更改為如下所示:

                  and you will get out image.mpc and image.cache. Then you would simply change your code to look like this:

                  convert -size 600x400 xc:none                                 
                      ( 1.mpc -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 2.mpc -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 3.mpc -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 4.mpc -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 5.mpc -fill rgb(x,y,z) -colorize 100% ) -composite  
                      ( 6.mpc -fill rgb(x,y,z) -colorize 100% ) -composite  
                      result.png
                  

                  第 3 點

                  很遺憾,您還沒有回答我的問題,但如果您的資產目錄不是太大,您可以在系統啟動時將其(或上面的 MPC 等效項)放到 RAM 磁盤上.

                  Unfortunately you haven't answered my questions yet, but if your assets catalogue is not too big, you could put that (or the MPC equivalents above) onto a RAM disk at system startup.

                  第 4 點

                  您絕對應該并行運行 - 這將產生最大的收益.使用 GNU Parallel 非常簡單 - 此處的示例.

                  You should definitely run in parallel - that will yield the biggest gains of all. It is very simple with GNU Parallel - example here.

                  如果您使用的是 REDIS,實際上比這更容易.只需 LPUSH 將您的 MIME 編碼圖像放入一個 REDIS 列表中,如下所示:

                  If you are using REDIS, it is actually easier than that. Just LPUSH your MIME-encoded images into a REDIS list like this:

                  #!/usr/bin/perl
                  ################################################################################
                  # generator.pl <number of images> <image size in bytes>
                  # Mark Setchell
                  # Base64 encodes and sends "images" of specified size to REDIS
                  ################################################################################
                  use strict;
                  use warnings FATAL => 'all';
                  use Redis;
                  use MIME::Base64;
                  use Time::HiRes qw(time);
                  
                  my $Debug=0;    # set to 1 for debug messages
                  
                  my $nargs = $#ARGV + 1;
                  if ($nargs != 2) {
                      print "Usage: generator.pl <number of images> <image size in bytes>
                  ";
                      exit 1;
                  }
                  
                  my $nimages=$ARGV[0];
                  my $imsize=$ARGV[1];
                  
                  # Our "image"
                  my $image="x"x$imsize;
                  
                  printf "DEBUG($$): images: $nimages, size: $imsize
                  " if $Debug;
                  
                  # Connection to REDIS
                  my $redis = Redis->new;
                  my $start=time;
                  
                  for(my $i=0;$i<$nimages;$i++){
                     my $encoded=encode_base64($image,'');
                     $redis->rpush('images'=>$encoded);
                     print "DEBUG($$): Sending image $i
                  " if $Debug;
                  }
                  my $elapsed=time-$start;
                  printf "DEBUG($$): Sent $nimages images of $imsize bytes in %.3f seconds, %d images/s
                  ",$elapsed,int($nimages/$elapsed);
                  

                  然后運行多個工人,他們都坐在那里做大量的工作

                  and then run multiple workers that all sit there doing BLPOPs of jobs to do

                  #!/usr/bin/perl
                  ################################################################################
                  # worker.pl
                  # Mark Setchell
                  # Reads "images" from REDIS and uudecodes them as fast as possible
                  ################################################################################
                  use strict;
                  use warnings FATAL => 'all';
                  use Redis;
                  use MIME::Base64;
                  use Time::HiRes qw(time);
                  
                  my $Debug=0;    # set to 1 for debug messages
                  my $timeout=1;  # number of seconds to wait for an image
                  my $i=0;
                  
                  # Connection to REDIS
                  my $redis = Redis->new;
                  
                  my $start=time;
                  
                  while(1){
                     #my $encoded=encode_base64($image,'');
                     my (undef,$encoded)=$redis->blpop('images',$timeout);
                     last if !defined $encoded;
                     my $image=decode_base64($encoded);
                     my $l=length($image);
                     $i++; 
                     print "DEBUG($$): Received image:$i, $l bytes
                  " if $Debug;
                  }
                  
                  my $elapsed=time-$start-$timeout; # since we waited that long for the last one
                  printf "DEBUG($$): Received $i images in %.3f seconds, %d images/s
                  ",$elapsed,int($i/$elapsed);
                  

                  如果我像上面一樣運行一個生成器進程并讓它生成 100,000 張圖像,每個圖像 200kB,并在我的合理規格 iMac 上用 4 個工作進程讀取它們,需要 59 秒,或者大約 1,700 張圖像/秒可以通過 REDIS.

                  If I run one generator process as above and have it generate 100,000 images of 200kB each, and read them out with 4 worker processes on my reasonable spec iMac, it takes 59 seconds, or around 1,700 images/s can pass through REDIS.

                  這篇關于使用 redis/php-resque 優化并發 ImageMagick 請求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  <tfoot id='qFwFP'></tfoot>

                    <bdo id='qFwFP'></bdo><ul id='qFwFP'></ul>

                    • <i id='qFwFP'><tr id='qFwFP'><dt id='qFwFP'><q id='qFwFP'><span id='qFwFP'><b id='qFwFP'><form id='qFwFP'><ins id='qFwFP'></ins><ul id='qFwFP'></ul><sub id='qFwFP'></sub></form><legend id='qFwFP'></legend><bdo id='qFwFP'><pre id='qFwFP'><center id='qFwFP'></center></pre></bdo></b><th id='qFwFP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qFwFP'><tfoot id='qFwFP'></tfoot><dl id='qFwFP'><fieldset id='qFwFP'></fieldset></dl></div>
                        1. <small id='qFwFP'></small><noframes id='qFwFP'>

                              <tbody id='qFwFP'></tbody>
                          • <legend id='qFwFP'><style id='qFwFP'><dir id='qFwFP'><q id='qFwFP'></q></dir></style></legend>
                            主站蜘蛛池模板: 亚洲欧美网站 | 亚洲精品乱码久久久久久久久 | 亚洲高清在线观看 | 亚洲激情一区二区三区 | 免费黄色的视频 | 自拍偷拍第一页 | 天天色图 | 久草视频在线播放 | 日韩小视频在线 | 欧美不卡 | 一区二区三区视频 | 一级黄色片在线看 | 亚洲视频二区 | 四虎成人免费视频 | 91精品国产手机 | 狠狠干天天干 | 日日综合| 成人在线视频观看 | 天堂一区二区三区四区 | 久久久亚洲 | 人人鲁人人莫人人爱精品 | 成人一区在线观看 | 久久久久久久久久久久久9999 | 精品国产青草久久久久96 | 黑人精品 | 亚洲精品一区二三区不卡 | 精品久久久久久久久久久久 | 精品久久久久一区二区国产 | 国产精品麻 | 国产电影精品久久 | 亚洲欧洲一区 | 日韩精品一区二区三区在线播放 | 国产欧美精品一区二区三区 | 成人网在线观看 | a级在线免费视频 | 欧美国产91 | 国产视频在线观看一区二区三区 | 久久久久久亚洲国产精品 | 国产高清在线视频 | 天色综合网| 久久精品免费一区二区三 |