riderkick / FMD

Forked from https://sf.net/p/fmd/
GNU General Public License v2.0
719 stars 213 forks source link

FMD use High CPU when download manga #919

Closed nattapan closed 6 years ago

nattapan commented 6 years ago

image

start with 0.9.131 till .133 FMD use much more CPU power to download file , image I use this setting before .131 but it didn't use that much of CPU power ,I notice this because of my NB breath out of very hot wind when I download chapters from manga sites

Thanks in advance.

kmvi commented 6 years ago

From which website you are downloading?

nattapan commented 6 years ago

before I download from MangaFox , but right now I switched to MangaRock

kmvi commented 6 years ago

Mangarock uses webp as image format. We have to convert it to PNG. We use official google codec for this. But unfortunately conversion process takes a lot of CPU resources. Other websites don't require image conversion.

riderkick commented 6 years ago

IIRC scanline is slow in fpc. http://wiki.freepascal.org/Fast_direct_pixel_access Try to use TFPCustomImage instead.

Or his download speed is to fast and he download to much to give his computer a break.

nattapan commented 6 years ago

I see , can you have an option to save as webp too ,my viewer support webp too. My download speed is around 10 - 50 Mbps. I suggest that must find some opencl codecs to handle this convert task.

Tmp341 commented 6 years ago

I think reducing the first two options might reduce system usage too. I always use 1 for "number of downloaded tasks" and "number of files". It is an habit from my Jdownloader times. It was slowing my internet usage, consuming a lot of ram etc.

nattapan commented 6 years ago

Of course reduce working threads will reduce CPU usage , But in my opinion I chose option to save as webp because my viewer has webp codec ,with this it kill two birds with one stone , 1 is reduce CPU usage ,2 is reduce files size , and I still got speed of my link too. P.S. after researched accelerated OpenCL codec for webp still nowhere found.

birdmanravo commented 6 years ago

Can we have the option to not convert the images to PNG? FMD is made for Windows and Windows can view WEBP images.

kmvi commented 6 years ago

I did a little research and it turned out that the problem actually is in TFPWritePNG, not in the decoder. I looked for how to replace this class. dwebp utility from libwebp distribution uses either WIC or libpng. BGRABitmap also looks promising. I'll try to experiment with these libraries...

riderkick commented 6 years ago

Encoding a png image is pretty straight forward, its lossless. Especially if we don't use palettes. But png can compress the stream using deflate. Maybe that's the problem. IIRC There is a compression level that we can adjust in png writer. I've been reading this unit when writing imp2pdf years ago.

BGRABitmap using the same reader/writer from fpc, with a bit of modification. I've been using BGRABitmap for my various projects for years. Its add about 2mb to binary size. So, I don't use it. We are not drawing anything advance for now.

riderkick commented 6 years ago

@kmvi please test https://github.com/riderkick/FMD/commit/1a19d243df2888389f7da386c67d4933fbffd590 and change it to clfastest if necessary.

kmvi commented 6 years ago

Benchmarking (webp size 1 321 542):

riderkick commented 6 years ago

That can be it. 1 second for compressing data. 8 thread with continuous process sure can give an overhead to the machine.

kmvi commented 6 years ago

JPEG benchmarking:

riderkick commented 6 years ago

We can make an options in Save to to save webp as webp,jpeg,png. Possibly also the options for compression level for png and jpeg. Store the global variable in FMDVars unit.

kmvi commented 6 years ago
kmvi commented 6 years ago

4 threads, 6 chapters.

Despite the high CPU utilization, the fastest mode looks the most reasonable.

riderkick commented 6 years ago

Please test and close if ok.

kmvi commented 6 years ago

It's ok, except that img2pdf cannot read raw webp. zip/cbz also not working unless conversion to png/jpg is set:

13:10:42:567 TTaskThread, failed to compress.

riderkick commented 6 years ago

zip/cbz just miss the webp extension.

riderkick commented 6 years ago

Well I guess we need to write TFPCustomImageHandler for webp and register it in ImgInfos. Just a reader is enough.

kmvi commented 6 years ago

I'll look into it

riderkick commented 6 years ago

After looking again at img2pdf, I think we don't need to write a new handler. Just register a method to read webp stream and size. And add new method in img2pdf to convert webp to png and read as png.

riderkick commented 6 years ago

@kmvi please test

kmvi commented 6 years ago

@riderkick :+1:

ralvarador commented 6 years ago

Then, It will be customizable the way that the files are converted; something like - convert all to JPG using "n Level Compression" - "optimum Huffman" - "progessive"... blah... blah.."? or, is this only for webp?

riderkick commented 6 years ago

Only for webp. Convert to jpg always degrade the quality and maybe increase the size compare to original. Some png file are smaller. I often found indexed png for black and white image. Converting other image doesn't really give much benefit. They usually already optimized for web page, which is optimized for smaller size.