Monday, 22 December 2014

Speed up your Wordpress 1.000x with REDIS

I was bored so I decided it was time to upgrade my server with new distro and switch to NGIX. My current installation was Debina6 PHP5.3 running Lighty web server. My typical cached server response was around 1s. Considering my server uses 12 CPUs this was really bad. But the page load is low and I didn't care to much:)

Having problem with
apt-get dist-upgrade 
in the past I decided rather to install fresh version of debian/jessi
 I like jesse because I got accustomed with systemd and jessie is finnaly on board with it.
I decided that I will also cut down on number of CPUs down to just 4 (AMD Buldozer 2Ghz) and 4Gb of ram.

So my new LAMP stack is now LNMP. Just migrating to NGINX and enabling OPCache the typical response time became 3-4x faster on 3x less CPUs. I didn't bother with server load at this point since this was just learning exercise.

Now my page load time was about 300ms. Things are getting brighter I thought.

But I was not happy yet. I found a great tutorial on how to configure Wordpress to use REDIS

https://www.rosehosting.com/blog/install-and-run-wordpress-cached-with-redis-on-linux-vps/

I don't like caching plugins like W3C because It has so much overhead and I like to use as few plugins as possible. Wordpress core is really great but plugins... Plugins are hell:)

Redis implementation to wordpress was however almost trivial. I took me 30 minutes to set thing up and push changes to production. And now a bomb shell.

 Page generated in ~0.84239 seconds Apache without php cache

Page generated in 0.34239 seconds  NGIX with OPCache

Page generated in 0.00084 seconds !!! NGIX wit OPCache and REDIS

I took just a few hours with almost no effort to archive 1.000x faster page load.

So to paraphrase Microsoft 365 commercial. UPGRADE UPGRADE UPGRADE




Thursday, 13 November 2014

Transcoding RM and WMA with Node.js under Windows

I just love Node.js!

You can do just about anything with it. My task was to transcode media files and keep the folder structure. I also had to check for media ype. RM videos, RM audio and WMA audio files were used at input.

Attention!
If you are planning to try it out you must install ffpmeg, mencoder and ffprobe. Make sure you add installed files to Windows path!

So first I used 'final-fs' => 'npm install final-fs' to read all files from my input forder and create the same folder structure at my output.

Because each file was different I had to use ffprobe => 'npm install node-ffprobe' to inspect media info. I using under windows you have tho change source file so it uses win-spawn. So also you need to 'npm install win-spawn'. We will also need win-spawn to spawn ffmpeg or mencoder processes...

So after we get media file info we are ready to use the appropriate codec...

You can check the code here. The code is robust because I took only a few hours to write but it does the job done!

https://github.com/dejancencelj/serial_trascode_videos



Wednesday, 12 March 2014

Simple way to copy multiple files under windows

The problem was simple. I had to copy a whole lot of files (from a txt file) from one location to another in order to optimize file structure. I was thinking about using batch scripting but than I realized that the only thing I really need is to use copy.exe. So other stuff like opening file, reading it line by line, parsing the line could be done in some simple manner. So I choose python that I haven't used since collage and give it a try. Phython is simple and all you need to do is just install execution environment, write a couple of line of code and It should work just fine.

So my input was:
154612818,28/21/BucenvstopvnovoletopovsejSlovenijix201301011400x700000x351x413x.mp4,2013/01/01/BucenvstopvnovoletopovsejSlovenijix201301011400x700000x351x413x.mp4
154612866,28/71/PrviletosnjinovorojenecjeAnjurx201301011334x700000x351x413x.mp4,2013/01/01/PrviletosnjinovorojenecjeAnjurx201301011334x700000x351x413x.mp4
154612881,28/84/Praznovanjenovegaletaposvetux201301011407x700000x351x413x.mp4,2013/01/01/Praznovanjenovegaletaposvetux201301011407x700000x351x413x.mp4


So first i had to open the file, splice it to get source and destination file and than just call copy function under windows. This is the result:


You have to have the fil you want to read from saved under same location in order to script to work.

Just open cmd.exe and run command py maypythoncopy.py and wait a bit:)