Thursday, 8 January 2015



Found some mysql-peformancce tuning parameters.  This can help if you have a medium scale  website or a blog hosting with mainly reads and very less writes. 

mysql> SHOW GLOBAL STATUS LIKE 'Com_select';
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Com_select    | 96212863 |
+---------------+----------+

Com_select gives the total number of selects which is almost same as Qcache_not_cached in our cache. 
Com_select = Qcache_inserts + Qcache_not_cached + queries with errors found during the column-privileges check

mysql> SHOW GLOBAL STATUS LIKE '%qcache%';
+-------------------------+----------+
| Variable_name                     | Value    |
+-------------------------+----------+
| Qcache_free_blocks            | 1        |
| Qcache_free_memory         | 1031352  |
| Qcache_hits                        | 0        |
| Qcache_inserts                   | 0        |
| Qcache_lowmem_prunes   | 0        |
| Qcache_not_cached           | 96212009 |
| Qcache_queries_in_cache | 0        |
| Qcache_total_blocks          | 1        |
+-------------------------+----------+


Configuration variables:

mysql> SHOW VARIABLES LIKE '%query_cache%';
+------------------------------+---------+
| Variable_name                         | Value   |
+------------------------------+---------+
| have_query_cache                    | YES     |      this value is always YES, even if query caching is disabled.
| query_cache_limit                     | 1048576 |  maximum size of individual query results that can be cached.
| query_cache_min_res_unit       | 4096    |      block size for query cache to allocate memory.
| query_cache_size                     | 1048576 |   Setting it to 0 disables the query cache.
| query_cache_type                     | OFF     |      If the query cache size is greater than 0, the query_cache_type variable influences how it works. 
| query_cache_wlock_invalidate | OFF     |       on WRITE, invalidate any queries in the query cache that refer to the table
+------------------------------+---------+


Additionally this article explains mysql-query cache pretty well 

I was able to validate most of the points in the article with the mysql documentation. But one point mentions that query caching  "Does not support prepared statements and cursors".

Last thing, 
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Select_full_join | 74593 |
+------------------+-------+
'The number of joins that perform table scans because they do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.'

Thursday, 29 August 2013

How to Create your Own Icon in Ubuntu

If you have just created your own script which does a lot of things and you want to save it as an application with an icon that has your image then read on :

Create a file with name as .desktop in your /usr/share/applications folder with content as following. 

Here is an example where I wanted to add some application (sublime IDE ) to GNOME task bar. All you have to do is replace Name=sublime with name of your aplication and then name your file accordingly(in my case sublime.desktop).



[Desktop Entry]
Version=1.0
Name=sublime
Comment=IDE
Exec=/home/vishu/Downloads/Sublime\ Text\ 2/sublime_text
Icon=/home/vishu/Downloads/Sublime Text 2/Icon/48x48/sublime_text.png
Terminal=false
Type=Application
Categories=Utility;Application;


  • Icon is the .png file you would like to use as your icon.

  • Exec is the path of you executable script or application

  • Make the file executable.

  • Now press windows start on your computer and type in the name in the GNOME search bar.
    You should be able to see the application getting launched.
    Right click and select Keep in Launcher to lock it there.




    Saturday, 17 August 2013

    CORS: WorkArounds | Part 1

    This piece of writing would try to summaries certain checkpoints all webdevelopers need to ensure when they are working with Cross-Origin Resource Sharing (CORS) :

    Domain

    So http://www.abc.nyc.com is a domain. Correct. But for your browser http://www.abc.xyz.com:80 and http://www.abc.xyz.com:90 are two different domains. This should be kept in mind always. Surely IE will treat these domains otherwise. Please google up if you are on IE.

    Resource Sharing

    Internet is the biggest open source community in itself. We constantly share our data when we are on net. Resource sharing can be seen as when a page on web requests for an information from the server which it may or may not own. This is done through http requests. This opens pandora's box of troubles both for service providers and consumers. Which requests to serve(server side) and which replies to accept(client side).

    Client side security is implemented by browsers and we will be speaking mainly about that.


    Useful Work Arounds:

    1. if you control the server and client append this information in your response headers:

                      response["Access-Control-Allow-Origin"] = "*"
     response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
     response["Access-Control-Max-Age"] = "1000"
     response["Access-Control-Allow-Headers"] = "*"

    2.to send and receive cookies over CORS:

                        response["Access-Control-Allow-Origin"] = "http://localhost"
       response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
       response["Access-Control-Max-Age"] = "1000"
       response["Access-Control-Allow-Headers"] = "*"
        response["Access-Control-Allow-Credentials"]="true"
    you CANNOT set    response["Access-Control-Allow-Origin"] = "*" while using Access-control-origins=true.


    3. if you are using ajax on client side and want to send and receive cookies set you xhr request header as:


    xhrFields: {
          withCredentials: true
          }


    recommended link : https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS




                             


    Wednesday, 7 August 2013

    ReInstalling Apache2

    What would definitely not work:

    1. sudo apt-get uninstall apache2
    2. sudo apt-get autoremove --purge
    Check:

    vishu@vishu-Lenovo-G470 ~$ whereis apache2
    Console o/p:
    --------------------------------------------------------------------------------------------------------
    apache2: /usr/sbin/apache2 /etc/apache2 /usr/lib/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz
    --------------------------------------------------------------------------------------------------------
    the night is longer my friend....

    What may seem to work but would not work:

    Astute readers may go to the above mentioned directories and delete these files. So go and try and come back if you fail ..........

    If you are still with me try deleting apache2 folder under /etc/var/ .............. and come back
     
    Check2:

    vishu@vishu-Lenovo-G470 ~$ whereis apache2
    Console:
    --------------------------------------------------------------------------------------------------------
    apache2:
    --------------------------------------------------------------------------------------------------------

    Is this a victory??? have you successfully removed apache2
    ???????? 

    Holdon,try this:
    vishu@vishu-Lenovo-G470 ~$ sudo pgrep -f 'apache2' 

    Do you see random 4 digit numbers ?? this means the work is yet not finish. Hit enter vociferously and relax.

    What may work:
    • sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common 
      apache2-mpm-prefork 
      apache2-mpm-worker
    • sudo apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2.2-common



    What definitely works:
    • sudo service apache2 stop
    • sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common 
      apache2-mpm-prefork 
      apache2-mpm-worker
    • sudo apt-get autoremove --purge
    • sudo apt-get install apache2
    FinalCheck:
    now open your browser and enter:

    This would display the index.html placed in your /var/www folder.