Around emacs, linux, etc.
WebTech
列举网页提速的几个原则和方法
Apr 14th
这两天在帮ld的discuz站做优化,不得不说,discuz在这方面还很不够,列一些原则和方法出来,供参考
提速通常从两方面入手
传输提速
- 下载提速
- 减少建立链接的次数
- keep-alive 旨在减少多次握手带来的开销 此外 404这样的错误会打断keep-alive 恐怕没多少人注意过这个问题吧
- 减少文件数 js,css的合并 多个图片合成一张 旨在减少http header
- 合理使用expire
- 减少数据量
- gzip
- 混淆精减js 精减css html 要知道 一个两千行的html 光是把换行和每行头的缩进去掉就至少是两三k!
- 减少服务端处理时间
- 利用服务端缓存减少服务端io时间 比如squid memcachd
- 减少建立链接的次数
- 上传提速
- 把资源类文件放在cookie free的域名上,减少不必要的上行数据
显示提速
- 减少dom层次
- 减少页面中间的js
discuz现在最让我头疼的就是资源图片太过零碎和dom嵌套层次太深
xinu, yslow
Jul 26th
曾经在哪看到的xinu忘了,今天找的时候开发者居然不提供服务了,不过提供了源码下载,所以在本站放了一个。链接是xinu,很不错的一个站点各项数据分析搜索引擎数据采集工具,唉,偶的网站数据小的可怜啊~~
xinu的源代码,php的
再来说说YSlow,分析你的网页为何加载的这么慢的一个工具,地址回头再给。
会针对你的网页比如css的放置,js的放置等等各项打分,给出改进速度的建议,不过我不明白为何不欢迎ETag……
用CPP做apache的module
Jul 15th
有三个地方要改
- 首先注释掉include/ap_config_auto.h里面的
- define AP_HAVE_DESIGNATED_INITIALIZER 1
- if (defined(__GNUC__) && !defined(__cplusplus)) \
|| (defined(__STDC_VERSION) && __STDC_VERSION__ > 199901L)
- define AP_HAVE_DESIGNATED_INITIALIZER 1
- endif
typedef const char *(*cmd_func) ();
为
- if (defined(__GNUC__) && !defined(__cplusplus)) \
|| (defined(__STDC_VERSION) && __STDC_VERSION__ > 199901L)
typedef const char *(*cmd_func) ();
- else
typedef const char *(*cmd_func) (cmd_parms*, void*, const char*);
- endif
apache module中取post数据
Apr 30th
一共使用三个函数
- ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)
Apache里面说Setup the client to allow Apache to read the request body. 差不多意思就是初始化,第二个参数可以取以下三个值。- REQUEST_NO_BODY
意为如果request必须没有body,如果有就发一个413错误 - REQUEST_CHUNKED_ERROR
意为request必须不可为chunked,如果有就发一个411错误 - REQUEST_CHUNKED_DECHUNK
意思为如果chunked了,则dechunk。
对于我们要读取post的数据,只能取后面两个,而chunked则是对长连接的选项了,使用哪个视情况而定。
- REQUEST_NO_BODY
- ap_should_client_block(r)
检查是否有数据,对于chunked的话会发送一个100 continue的命令让客户端继续发送数据。 - ap_get_client_block(r, pBuff, size)
读取数据
apache及其module的调试
Apr 30th
- gdb httpd
用gdb加载httpd进程 - (gdb) b break-point
设置断点,可以设置函数名、行数等…… - (gdb) run -X -d /usr/local/apache
执行httpd,这个是关键的,-X参数会让httpd以debug模式运行,debug模式是单进程的,这样才好调试。-d /usr/local/apache是设置运行的目录。
另外,gdb httpd pid可以attach一个正在运行的httpd来调试。
About module struct in Apache
Apr 4th
在写apache模块的时候,会用到module这个结构体。module这个结构体实际上是module_struct,后面附上了定义。使用的时候通常都是定义一个这个结构体的变量并赋初值,如:
module AP_MODULE_DECLARE_DATA proxy_module =
{
STANDARD20_MODULE_STUFF,
create_proxy_dir_config, /* create per-directory config structure */
merge_proxy_dir_config, /* merge per-directory config structures */
create_proxy_config, /* create per-server config structure */
merge_proxy_config, /* merge per-server config structures */
proxy_cmds, /* command table */
register_hooks
};
其中STANDARD20_MODULE_STUFF这个宏为module_struct中的API version, minor version, module index, name, danamic load handle, next, magic, rewrite_args赋了初值。随后是per-directory configuration structure的初始化、合并函数和per-server configuration structure的初始化、合并函数。command table是command_rec结构的一个数组,依然是宏展开,描述这个模块在配置文件里面的信息。最后的register_hooks指向用于注册hook的函数。
typedef struct module_struct module; /**
- Module structures. Just about everything is dispatched through
- these, directly or indirectly (through the command and handler
- tables).
- /
- compatible with this version of the server.
- /
- during module init */
- @defvar module_struct *next */
- important for the DSO facility (see also mod_so). */
- hook is only available to MPMs.
- @param The process that the server is running in.
- /
- structures.
- @param p The pool to use for all allocations.
- @param dir The directory currently being processed.
- @return The per-directory structure created
- /
- structures for two directories.
- @param p The pool to use for all allocations.
- @param base_conf The directory structure created for the parent directory.
- @param new_conf The directory structure currently being processed.
- @return The new per-directory structure created
- /
- structures.
- @param p The pool to use for all allocations.
- @param s The server currently being processed.
- @return The per-server structure created
- /
- structures for two servers.
- @param p The pool to use for all allocations.
- @param base_conf The directory structure created for the parent directory.
- @param new_conf The directory structure currently being processed.
- @return The new per-directory structure created
- /
- defines. */
- In this function, modules should call the ap_hook_*() functions to
- register an interest in a specific step in processing the current
- request.
- @param p the pool to use for all allocations
- /
Apache中的挂钩剖析
Apr 4th

Recent Comments