Posts Tagged ‘Optimize’

PHP Optimization

Wednesday, October 10th, 2007 by hejian

Please read my essay Apache Optimization first.

For PHP scripts, the main bottleneck is the CPU. For static HTML/images, the bottleneck is RAM and the network. A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.

Enable the compression of HTML by putting in your php.ini:

output_handler = ob_gzhandler

Switch from file based sessions to shared memory sessions:
Compile PHP with the –with-mm option and set session.save_handler=mm in php.ini.

Firefox Optimization

Sunday, September 23rd, 2007 by hejian

Configure Level Optimization

Reducing memory usage

Useful Add-ons:
Cache Status

Preferences -> Privacy:
disable Remember what I’ve downloaded

Use these settings at about:config:

browser.cache.memory.capacity 12288
browser.cache.memory.enable true
browser.history_expire_days 7
browser.sessionhistory.max_total_viewers 0

Optimize Speed
Disabling pango, it’s really slow, put this in ~/.bash_profile:

export MOZ_DISABLE_PANGO=1

Use these settings at about:config:

network.dns.disableIPv6 true
network.http.max-connections 32
network.http.max-persistent-connections-per-server 4
network.http.max-persistent-connections-per-proxy 8
network.http.pipelining true
network.http.pipelining.maxrequests 8
network.http.proxy.pipelining true

Compile Lever Optimization

The instruction for compiling firefox in here are based on Fedora.

Adjust the CFLAGS in /usr/lib/rpm/rpmrc for your target, and then select the correct target when build rpm:

rpmbuild -ba firefox.spec --target=i686

Code Level Optimization

I have not start the testing of code level optimization yet. Please let me know if you have any suggestion.

Leak detection tool: leak-monitor

Rendering Speed Test
Just need create a html file and this to head:

<script type="text/javascript">
// <![CDATA[
startDate = new Date();
startTime = startDate.getTime() / 1000;
function calceRenderingTime()
{
endDate = new Date();
endTime = endDate.getTime() / 1000;
alert(endTime - startTime);
}
// ]]>
</script>

and then invoke calceRenderingTime in body’s onload:

<body onload="calceRenderingTime();">

osCommerce query optimization

Saturday, May 5th, 2007 by hejian

Optimization Contributions
Output Queries Debug (2575)
Page Cache (2561)
tep_get_path optimization (4052)
tep_show_category optimization (4075)

Admin Configuration
Configuration -> My Store -> Show Category Counts : false

Most Important MySQL Configuration variables for performance

Monday, February 12th, 2007 by hejian

Show Variables
mysql> SHOW VARIABLES LIKE ‘%buffer%;
or:
shell> mysqladmin variables

Set Variables
mysql> SET GLOBAL key_buffer_size = 10000000;
or:
set it in my.ini

The following are the most important configuration variables in terms of overall performance:

key_buffer_size
Size of the buffer used for index blocks. On a dedicated server, this should usually be about 25% of total RAM. Depending on the operating system, you may be able to increase it beyond this value, but anything above 50% of RAM is liable to be counterproductive due to paging effects caused by the fact that MySQL does not cache data reads from the files, leaving this to be handled by the operating system.

table_cache
Number of open tables for all threads. If your application requires a lot of tables to be open at the same time, try increasing the size of the table_cache variable.

You can see if this needs to be increased by checking the value of the Open_tables variable.

read_buffer_size
Each thread that does a sequential scan allocates a buffer of this size for each table it scans.

If you do many sequential scans(check the value of Handler_read_rnd_next), you should first try adding table indexes or optimizing existing ones. If that doesn’t work or isn’t feasible, you may want to increase this value.

sort_buffer_size
Size of the sort memory buffer allocated to each thread. This can be increased to speed up ORDER BY and GROUP BY queries. The default is 2MB.

If you’re doing a lot of ORDER BY and/or GROUP BY queries that return large resultsets, you may find that increasing the value of sort_buffer_size helps. You may need to experiment with this. Try increasing it in increments of 5% to 10% of the starting value to see if and by how much this speeds up large queries of this type.

net_buffer_length
Size to which MySQL’s communication buffer is reset between queries. This normally should not be changed; however, to gain a small performance improvement on systems with little memory, it can be can set to the expected length of SQL statements sent by clients.

In situations where memory is at a premium or you have a very high number of connections, you may be able to improve matters by adjusting the size of net_buffer_length. However, if you set this value to be too small, you’ll waste any performance gain you might have otherwise obtained, because MySQL will need to keep resetting this value in order to accommodate queries that are longer than the stated number of bytes.

MySQL Optimization

Monday, February 12th, 2007 by hejian

Starting Question
What version of MySQL are you using?
Which operating system?
MySQL dedicated or shared servers?
How fast is your growth? Thansaction rates, Data volumn

Need to Know
Operation system basics: Memory usage, swapping

MySQL’s Defaults
Tuned for small and medium data sets
Uses very little memory even if available
Suitable for use in a shared environment
Assumes little about your hardware
Begins to slow as growth continues
Uses non-transactional table (MyISAM): mose people need (90%), very low overhead

Operating System Tuning Tools
mytop: a console-based tool for monitoring the threads and overall performance of a MySQL server.
top, ps, vmstat
iostat, sar
mrtg, rrdtool

mysqld –verbose –help
mysqladmin extended-status

Important MySQL startup options
Find the bottlenecks:
long_query_time=1
log_slow_queries=slow_query.log
log-queries-not-using-indexes

table_cache: if the value Opened_tables is too big, so need increase the table_cache.
key_cache: if the value of Key_reads/Key_read_requests is too big, so need to increase the key_cache.

back_log Change if you do a lot of new connections.
thread_cache_size Change if you do a lot of new connections.
key_buffer_size Pool for index pages; Can be made very big
bdb_cache_size Record and key cache used by BDB tables.
delay_key_write Set if you need to buffer all key writes
max_heap_table_size Used with GROUP BY
sort_buffer Used with ORDER BY and GROUP BY
myisam_sort_buffer_size Used with REPAIR TABLE
join_buffer_size When doing a join without keys

Wordpress template made by HeJian