FreeBsd 6.2 下 Squid 开启大内存导致进程内存溢出
Post by newdir. Oct 7, 2008 Web开发
Freebsd 6.2 的服务器, 跑Squid服务,经常在启动不久之后,就会出现
xcalloc: Unable to allocate 1 blocks of 4108 bytes!
错误信息,大致是指Squid申请内存错误。
在 Squid FAQ 中找到
Messages like "FATAL: xcalloc: Unable to allocate 4096 blocks of 1 bytes!" appear when Squid can't allocate more memory, and on most operating systems (inclusive BSD) there are only two possible reasons:
* The machine is out of swap
* The process' maximum data segment size has been reached
The first case is detected using the normal swap monitoring tools available on the platform (pstat on SunOS, perhaps pstat is used on BSD as well).
To tell if it is the second case, first rule out the first case and then monitor the size of the Squid process. If it dies at a certain size with plenty of swap left then the max data segment size is reached without no doubts.
The data segment size can be limited by two factors:
* Kernel imposed maximum, which no user can go above
* The size set with ulimit, which the user can control.
When squid starts it sets data and file ulimit's to the hard level. If you manually tune ulimit before starting Squid make sure that you set the hard limit and not only the soft limit (the default operation of ulimit is to only change the soft limit). root is allowed to raise the soft limit above the hard limit.
文中指出,导致 Squid在 Freebsd下跑起来内存溢出有两种情况:
1、系统的交换分区 Swap分区不够用。
2、进程申请的最大内存受到限制。
该服务器有4G内存,开启了高达8G Swap,明显第一个原因是不对。
然后用top 观察Squid运行状态,发现Squid在跑超过512M内存的时候,就自动退出了,而Squid设置的是1280M的内存参数。
用 limits 查看系统参数,发现单进程的内存占用数被限制在了512M
datasize 524288
通过 ulimt -d 2097152 和 ulimit -Hd 进行强制设置并不成功,因为freebsd默认是csh,不支持ulimit。
继续翻阅Google上的资料,在一个台湾网友那里找到了设置的方法。
将
kern.maxdsiz=”2G”
添加到
/boot/loader.conf
(中间尝试添加到 /etc/sysctl.conf 重启后不成功)
最新版JS框架scriptaculous一个bug修复
Post by newdir. Aug 22, 2008 Web开发
Script.Aculo.Us是基于Prototype框架的一个非常优秀的开源JS框架,详细的介绍和使用方法参见:
Script.aculo.us开发系列全集
这里记录下最新版1.8.1的一个bug:
该bug在InPlaceCollectionEditor控件中,该控件的作用是编辑状态下显示一个Select标签。但是在最新的1.8.1中调用该控件使会发生JS错误,无法成功,就连官方自带的demo文档下,该控件也无效。而老的1.6却不会出错。
经检测,错误发生在controls.js的838行: this._controls.editor.update(”);
这行代码在FIFEFOX下不会有问题,但是在IE下却会出错了,去掉该行即可,我估计写这个框架的老外用的是FF,所以这个BUG居然没发现,^_^。
MySQL 外键的设置及作用
Post by newdir. Sep 2, 2007 Web开发
外键的作用:
保持数据一致性,完整性,主要目的是控制存储在外键表中的数据。 使两张表形成关联,外键只能引用外表中的列的值!
例如:
a b 两个表
a表中存有 客户号,客户名称
b表中存有 每个客户的订单
有了外键后
你只能在确信b 表中没有客户x的订单后,才可以在a表中删除客户x
建立外键的前提: 本表的列必须与外键类型相同(外键必须是外表主键)。
指定主键关键字: foreign key(列名)
引用外键关键字: references <外键表名>(外键列名)
事件触发限制: on delete和on update , 可设参数cascade(跟随外键改动), restrict(限制外表中的外键改动),set Null(设空值),set Default(设默认值),[默认]no action
例如:
outTable表 主键 id 类型 int
创建含有外键的表:
create table temp(
id int,
name char(20),
foreign key(id) references outTable(id) on delete cascade on update cascade);
说明:把id列 设为外键 参照外表outTable的id列 当外键的值删除 本表中对应的列筛除 当外键的值改变 本表中对应的列值改变。
PHP编码规范
Post by newdir. Aug 3, 2007 Web开发
注:这是从PHPCMS开发文档里看到编码规范,虽名为PHPCMS的开发规范,但我觉得所有的PHP编程都该如此。写了那么多PHP,很多编码对照这规范都感觉欠缺很多,今后一定要对照纠正。
Phpcms 编码规范 Read the rest of this entry »
1. 引言…. 2
2. 适用范围…. 2
3. 标准化的重要性和好处…. 3
4. PHP编码规范与原则…. 3
4.1. 代码标记… 3
4.2. 注释… 3
4.3. 书写规则… 4
4.3.1. 缩进… 4
4.3.2. 大括号{}、if和switch. 4
4.3.3. 运算符、小括号、空格、关键词和函数… 5
4.3.4. 函数定义… 6
4.3.5. 引号… 6
4.3.6. 多语言问题… 7
4.4. 命名原则… 8
4.4.1. 变量、对象、函数名… 8
4.4.2. 常量… 8
4.5. 变量的初始化与逻辑检查… 8
4.6. 安全性… 9
4.7. 兼容性… 9
4.8. 代码重用… 10
4.9. 其他细节问题… 10
4.9.1. 包含调用… 10
4.9.2. 错误报告级别… 11
5. 数据库设计…. 11
5.1. 字段… 11
5.1.1. 表和字段命名… 11
5.1.2. 字段结构… 11
5.2. SQL语句… 12
5.3. 性能与效率… 13
5.3.1. 定长与变长表… 13
5.3.2. 运算与检索… 13
5.3.3. 结构优化与索引优化… 14
5.3.4. 查询优化… 14
5.3.5. 兼容性问题… 16
6. 模板设计…. 16
6.1. 代码标记… 16
6.2. 书写规则… 16
6.2.1. HTML. 16
6.2.2. 变量… 16
6.2.3. 语言元素… 17
6.2.4. 缩进… 17
7. 文件与目录…. 17
7.1. 文件命名… 17
7.2. 目录命名… 18
7.3. 空目录索引… 18
Linux下解决squid的filedescriptors问题
Post by newdir. Jun 11, 2007 Web开发
今日squid的日志文件经常报错:
WARNING! Your cache is running out of filedescriptors
查网上资料得知:filedescriptors为文件描述符 Read the rest of this entry »
MySQL优化步骤及my.cnf缓存优化
Post by newdir. Jan 5, 2007 Web开发
1、看机器配置,指三大件:cpu、内存、硬盘
2、看mysql配置参数
3、查系mysql行状态,可以用mysqlreport工具来查看
4、查看mysql的慢查询
依次解决了以上问题之后,再来查找程序方面的问题
