Tuesday, May 14, 2019

test

Monday, July 23, 2012

BlackBerry App World Wireless problem solved

popular blackberryProblem
In blackberry , we can use the browser with no problem but when we go to use blackberry app world it uses the mobile network internet , so  do we fix that.


when you try to connect the blackberry app using wireless app world , it says 
"You do not have sufficient wireless coverage or your connection to the wireless network is turned off"


Solution:
You need a BB(blackberry) data plan, as you can't use app-world without a BB data plan.
This was done intentionally  

Monday, July 16, 2012

Tabular comparison of MYISAM INNODB

FACTOR INNODB  MYISAM
Locking Row Level Table Level
Transaction Allowed Not Allowed
crash recovery Reliable Less Reliable
Referential integrity (FOREIGN KEYs) Supported Not Supported
Insert / Updates Speed Faster because of row level locking slower because of table level locking
Concurrent Insertion If update/inserted rows are different , then the operation can be perormed simultanosly No
Concurrent Updation If update/inserted rows are different , then the operation can be perormed simultanosly No
Concurent insert and updates If update/inserted rows are different , then the operation can be perormed simultanosly If a MyISAM table has no holes in the data file (deleted rows in the middle), an INSERT statement can be executed to add rows to the end of the table at the same time that SELECT statements are reading rows from the table. If there are multiple INSERT statements, they are queued and performed in sequence, concurrently with the SELECT statements.
Large number of selects as compared to inserts/delete comparatively slow fast
storage limit 1/4x than myisam 4x than innodb
full-text search No No
system resources High Low
Count(*) speed is slow Fast
Backing Up Difficult Easy,  just need to copy FRM , MYD & MYI files.

Calling Functions Using Variable In Php

Problem Statement:
In Order to optimize my code , I was thinking how to write the last two lines of code in one statement.
$v1 = functionName;
$strR = "get".$v1;
echo $obj->$strR();     
as i wana get $obj->getfunctionName();


Solution :
echo $obj->{"get" . $v1}();


Reason :
1. Bench marking reports suggest the solution is optimized.
2. Code looks more professional.

php elephant

Monday, June 25, 2012

Mysql Optimization - Find Remove Duplicate Indexes

Duplicate index means when we have multiple index in the same column of a table.

Example : duplicate on same column
CREATE TABLE DUPLICATE_INDEX (
  EMAIL varchar(100) NOT NULL,
  PRIMARY KEY (EMAIL),
  KEY EMAIL(EMAIL)
) ENGINE=MyISAM

In this example on column 'EMAIL' we have primary key and index as well and one of them is unnecessary. So ideally we should remove one of index from this table.

Example : duplicate because of composite index
CREATE TABLE DUPLICATE_INDEX (
  EMAIL varchar(100) NOT NULL,
  PHONE varchar(100) NOT NULL,
  UNIQUE KEY (EMAIL,PHONE),
  KEY EMAIL(EMAIL)
) ENGINE=MyISAM

In this example index on column is multiple because of index key EMAIL and UNIQUE key (EMAIL,PHONE) .so key on index EMAIL is irrelevant.

Why we need to remove these duplicate keys
1. They make the optimizer phase slower because MySQL needs to examine more query plans.
2. For every insert / delete / update  , the storage engine needs to maintain, calculate and update more index
3. Disk space will increase and hence the backup time.

How To Find Duplicate Keys
There is a tool in Percona Toolkit that can help you to find all those keys in your schema, its name is pt-duplicate-key-checkerand it can find the  different types of duplicates key


command: pt-duplicate-key-checker --database=test
Mysql Peformance


Sphinx Search Optimization

Sphinx search is an alternative of performing search in mysql .
From my experience sphinx will provide you a great deal of performance .
For Details http://sphinxsearch.com

This Page is about the optimization that i had done and will boost your performance

* Caching (Use Memcache)
sphinx directly does not support caching. An alternative is to use memcache. 
Based on your website requirements , say i fetch records of 1st 10 pages  and store records in memcache. So when user uses pagination then there is no need to peform a search operation , rather we can fetch records directly from memcache

* Use Of Multiquery / faceted searching
Multi-queries, or query batches, let you send multiple queries to Sphinx in one go.Two API methods that implement multi-query mechanism are AddQuery() and RunQueries(). 


Why To Use:
1. decrease in network roundtrips. 
2. automatic internal optimizations.
3. for new version performance will always increase.


Sequential Code
$cl->SetGroupBy('grouping1', SPH_GROUPBY_ATTR,"@count desc");
$cl->AddQuery ('textToSearch_OPTINAL','IndexName');
$res=$cl->RunQueries();

$cl->SetGroupBy('grouping2', SPH_GROUPBY_ATTR,"@count desc");
$cl->AddQuery ('textToSearch_OPTINAL','IndexName');
$res=$cl->RunQueries();

$cl->SetGroupBy('grouping3', SPH_GROUPBY_ATTR,"@count desc");
$cl->AddQuery ('textToSearch_OPTINAL','IndexName');
$res=$cl->RunQueries();

can be optimized by Multiquery
$cl->SetGroupBy('grouping1', SPH_GROUPBY_ATTR,"@count desc");
$cl->SetGroupBy('grouping2', SPH_GROUPBY_ATTR,"@count desc");
$cl->SetGroupBy('grouping3', SPH_GROUPBY_ATTR,"@count desc");
$cl->AddQuery ('textToSearch_OPTINAL','IndexName');
$res=$cl->RunQueries();

* Avoid use of setSelect('limitedcolumns)
setSelect(*) is much faster than setSelect('limitedcolumns)
Reason:
You have a bucket of colored marbels.If I ask you to pass me all (the *), then you just pass me the bucket.But if I ask you to pass me only the red and yellow ones, it takes you time, because you
have to pick out the right ones, and put them in a new bucket.
Smaller bucket (ie less network bandwidth), but takes longer (processing)

Sphinx Search

* Use Of SphinxQL (for large in/not-in queries)

client end computations are very high specially when a lot of values are being sent
in a IN or NOT IN clause because for every value it converts it into some binary format
using pack function and then sends to the sphinx server. This causes high load on our web
server because we have queries wherein we show online users within a search criteria and
sometimes online users are around 15k-20k.

example:  normal use of api is slow and cpu utilization consuming

for($i=100;$i<20000;$i++) {        $x[]=$i; }

$cl->SetFilter('PROFILEID',$x,TRUE);
use of sphinxQL will give cpu utilization improvement by 10 times

Distributed searching
To scale well, Sphinx has distributed searching capabilities. Distributed searching is useful to improve query latency (ie. search time) and throughput (ie. max queries/sec) in multi-server, multi-CPU or multi-core environments. This is essential for applications which need to search through huge amounts data (ie. billions of records and terabytes of text).

* Explore sphinx.conf
1. mem_limit                       = 32M (default allocation)
change it to around 2048MB based on your usage.

Tuesday, May 1, 2012

Reduce / Increase Image Size : Linux Command

Command To Reduce Image Size By x%
command :
convert -resize x% source.jpg new.jpg
For example :
to reduce size by 20% of image source.jpg
convert -resize 20% source.jpg new.jpg
target image new.jpg is 20% less of size
Reduce / Increase Image Size Linux

Command To Increase Size Image By x%
command :
convert -resize x% source.jpg new.jpg
For example :
to increase size by 120% of image "source.jpg"
convert -resize 120% source.jpg new.jpg
target "image new.jpg" is 120% more of size