Skip to content

Instantly share code, notes, and snippets.

View liujingyu's full-sized avatar

jingyu liu liujingyu

View GitHub Profile
@liujingyu
liujingyu / httpd.conf
Created May 25, 2015 11:11
apache 参数配置
线程数优化
Prefork优化的关键在于MaxClients与MaxRequestsPerChild。
MaxClients最佳的值:
apache_max_process_with_good_perfermance < (total_hardware_memory /apache_memory_per_process ) * 2
apache_max_process = apache_max_process_with_good_perfermance * 1.5
计算httpd平均占用内存
@liujingyu
liujingyu / intro
Last active February 20, 2023 12:50
mysql explain解读
id selecttype table type possible_keys key key_len ref rows extra各列。
其中:
type=const表示通过索引一次就找到了;
key=primary的话,表示使用了主键;
type=all,表示为全表扫描;
key=null表示没用到索引。
type=ref,因为这时认为是多个匹配行,在联合查询中,一般为REF。
前者可以得出一个表的字段结构等等,后者主要是给出相关的一些索引信息,而今天要讲述的重点是后者。
举例
@liujingyu
liujingyu / profile
Created May 29, 2015 06:58
关于PHP性能优化(转)
1、升级硬件的一般规则:对于 PHP 脚本而言,主要的瓶颈是 CPU ,对于静态页面而言,瓶颈是内存和网络。一台 400 Mhz 的普通奔腾机器所下载的静态页面就能让 T3 专线(45Mbps)饱和。
2、Apache 处理 PHP 脚本的速度要比静态页面慢 2-10 倍,因此尽量采用多的静态页面,少的脚本。
3、PHP 脚本如果不做缓冲,每次调用都需要编译,因此,安装一个 PHP 缓冲产品能提升 25-100% 的性能。
4、把基于文件的会话切换到基于共享内存的会话。编译 PHP 时采用 --with-mm 选项,在 php.ini 中设置 setsession.save_handler=mm 。这个简单的修改能让会话管理时间缩短一半。
5、另外一项缓冲技术是把不常修改的 PHP 页面采用 HTML 缓冲输出。
@liujingyu
liujingyu / abc.php
Created May 29, 2015 08:03
php redis session 配置
1.修改php.ini中session配置:
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://192.168.1.10:6379');
//redis有密码的话
//ini_set('session.save_path', 'tcp://192.168.1.10:6379?auth=password');
注意:php-fpm.conf中的配置会覆盖php.ini中的配置,所以要确保php-fpm中的对应配置关闭,或者修改:
@liujingyu
liujingyu / tools.sh
Created May 29, 2015 11:45
InnoDB表结构在线更改工具
随着互联网应用的发展,MySQL数据库的使用也越来越广泛,但是在使用过程中存在或这样或那样的棘手的问题,
其中在线更改表结构和索引,MySQL最好用的存储引擎InnoDB会将所有的写堵塞掉,进一步会堵塞读,从而造成线上业务的不可用,
这在很多情况下是不可接受的。
为了避免这种情况,一直以来可以通过主从复制加以解决,但是操作相对复杂,对于面对成百上千的MySQL数据库,显然成本太高。
为了解决这一矛盾,已经有前人做了工作,我们后人可以乘凉了,下面两款工具,可以帮助解决在有主键的情况下,在线更改表结构。
Python写的 oak-online-alter-table
https://code.google.com/p/openarkkit/source/browse/trunk/openarkkit/src/oak/oak-online-alter-table.py
@liujingyu
liujingyu / mem used
Created June 2, 2015 07:11
CentOS下top和free命令查看系统中空闲内存
下面介绍使用top和free命令查看系统中空闲内存
所以你执行top命令看到的
[root@linuxzgf ~]# top
Mem: 8174492k total, 7124268k used,并不是代表你的应用程序已经使用了7.1的内存,这7.1G是包含了:应用程序内存 + 缓冲 + 缓存的内存的,需要用free命令查看.
下面是一个例子(单位是MB):
[root@linuxzgf ~]# free -m
total used free shared buffers cached
Mem: 7982 6811 1171 0 350 5114
@liujingyu
liujingyu / yum
Created June 5, 2015 06:57
PHP编译安装时常见错误解决办法
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install libxslt-devel
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
yum install net-snmp-devel
configure: error: Please reinstall readline - I cannot find readline.h
yum install readline-devel
configure: error: Cannot find pspell
@liujingyu
liujingyu / io
Last active August 29, 2015 14:22
IO性能检测
#查看I/O性能
iostat -xm 1
首先找出来磁盘IO操作比较多的进程。这次使用的神器是iotop
iotop -d 1 -obk -a | cut -c -200
#参数-m是以M单位显示,默认K
@liujingyu
liujingyu / php-fpm
Last active April 26, 2016 06:59
php-fpm 启动脚本
#!/bin/sh
#
# php-fpm - this script starts and stops the php-fpm daemin
#
# chkconfig: - 85 15
# processname: php-fpm
# config: /usr/local/php/etc/php-fpm.conf
set -e
@liujingyu
liujingyu / find_relative_path.func.php
Created October 13, 2016 03:14 — forked from ohaal/find_relative_path.func.php
Find the relative path between two paths
/**
*
* Find the relative file system path between two file system paths
*
* @param string $frompath Path to start from
* @param string $topath Path we want to end up in
*
* @return string Path leading from $frompath to $topath
*/
function find_relative_path ( $frompath, $topath ) {