2006/05/11
utf-8 保存文件的 bom 问题
大家都知道 utf-8 是一种在web应用中经常使用的一种 unicode 字符的编码方式,使用 utf-8 的好处在于它是一种变长的编码方式,对于 ANSII 码编码长度为1个字节,这样的话在传输大量 ASCII 字符集的网页时,可以大量节约网络带宽。
不过如果大家使用 utf-8 编码来编写网页的时候, 往往会因为 bom (Byte Order Mark) 的问题,导致网页中经常出现一些不明的空行或者乱码字符。 这些都是因为 utf-8 编码方式对于 bom 不是强制的。因此 utf-8 编码在保存文件的时候,会出现不同的处理方式。
比如有的浏览器(FireFox)可以自动过滤掉所有 utf-8 bom , 有的 (IE) 只能过滤掉一次 bom (为什么是一次? 当你出现 Include 多次文件时就会碰上这个问题了:) );
对此 w3.org 标准 FAQ 中对此问题有一个专门的描述:
http://www.w3.org/International/questions/qa-utf8-bom
在此个人认为对于这个问题最好的处理方式就是在编辑(保存)文件的时候统一去除 utf-8 bom , 同时又必须使得编辑器可以正确读出 utf-8 字符集,但可惜目前 windows 系统中对于保存文件的处理方式缺省情款下都会自动加上 bom.
(通过抓包工具分析, google 中文页面统一使用 utf-8 编码方式,下载的页面中没有带有 bom 标识)
操作系统: WindowsXP Professional , 缺省字符集:中文
1) notepad : 可以自动识别出没有带 bom 的 utf-8 编码格式文件,但不可以控制保存文件时是否添加 bom , 如果保存文件,那么会统一添加 bom 。
2)editplus : 不能自动识别出没有 bom 的 utf-8 编码格式文件,保存文件为 utf-8 时会自动添加 bom
3) UltraEdit : 对于字符编码的功能最为强大, 可以自动识别带 bom 和不带 bom 的 utf-8 文件 (可以配置) ; 保存的时候可以通过配置选择是否添加 bom.
(特别需要注意的是,保存一个新建立的文件时,需要选择另存为 utf-8 no bom 格式)
后来发现 Notepad ++ 也对于 utf-8 bom 支持比较好,推荐大家使用。
阿涂 发表于 2006-05-11 10:42 阅读( 2889) 评论( 4) 引用( 5) 字符编码
2006/05/10
Prototype 文档
Prototype: http://prototype.conio.net/
是一个比较有名的 web2.0 (Ajax) 时代 Javascript lib 库,但其缺乏一定的文档,使得使用起来比较困难。
这里有不少人通过自己查看源代码,撰写了第三方的文档,
英文的:http://www.sergiopereira.com/articles/prototype.js.html
中文的:https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html
阿涂 发表于 2006-05-10 11:17 阅读( 1244) 评论( 0) 引用( 5) javascript
2006/05/06
设计模式资料
Principles of Object-Oriented Software Development
2nd edition
http://www.cs.vu.nl/~eliens/online/oo/contents.html
其中关于 Reactor 的一篇介绍:
slide: The Reactor pattern
The abstract layout of the software architecture needed to realize the pattern is depicted in slide reactor-structure. The reactor environment must allow for binding handlers to particular types of events. In addition, it must be able to receive events, and select a handler to which the event can be dispatched.
![]()
原文网址: http://www.cs.vu.nl/~eliens/online/oo/I/2/reactor.html
阿涂 发表于 2006-05-06 14:03 阅读( 1256) 评论( 0) 引用( 6) 技术
2006/05/04
JGroups Performance Test from official site
结果大于 10k messages/ second ,这样的性能感觉不错。 (每个 message 1k)
并且JGroups 已经支持了 java nio ,这样当节点再增加时不会因为 Thread 的增多而导致性能下降。
测试结果如下:
The JGroups PerfTests (http://wiki.jboss.org/wiki/Wiki.jsp?page=PerfTests) measures the time to send N messages to all members of a group. It computes messages/sec and throughput for each member in the group. Each machine was configured to be a sender and receive every message sent. Each machine sends 1,000,000 messages.
Test Run #
Number of messages read per second
1
13402
2
13155
3
13344
4
13107
Test results using TCP
Test Run #
Number of messages read per second
1
13490
2
13462
3
13476
4
13440
![]()
A 20 million message test was also run to ensure that there are no memory leaks.
测试环境:
Configuring Reader, Writer and Processor Threads
TCP_NIO has configuration settings for the number of reader, writer and processor threads. Generally, setting the number of threads to a smaller number is better than a larger number. As a starting point, try:
reader_threads = 8 * number of CPUs
writer_threads = 8 * number of CPUs
processor_threads = 8 * number of CPUs
processor_minThreads = 8 * number of CPUs
processor_maxThreads = 8 * number of CPUs
processor_keepAlivetime = -1
processor_queueSize = 100
The reader threads read incoming requests and hand the request off to the processor threads to be handled. The processor threads may be disabled (processor_maxThreads is set to zero) so that the incoming requests are handled in the reader threads.
If processor_minThreads is less than processor_maxThreads, new threads will be created to process requests, if and only if, the processor internal queue has processor_queueSize entries in it. This occurs at the time that the next request needs to be processed.
If the internal queue is full and processor_maxThreads threads are busy, the reader thread will block until one of the processor threads completes its work.
Testing environment
Cluster: 4 Dell Optiplex GX260 machines
CPU: Three Intel Pentium 4 2.26GHz and one Pentium 4 2GHz
Memory: 1GB
OS: SUSE Linux Enterprise Server 9 (kernel: 2.6.5)
Switch: 100Mega bit
JGroups configuration file<config>
<TCP_NIO bind_addr="164.99.218.115" recv_buf_size="20000000" send_buf_size="640000"
loopback="false" discard_incompatible_packets="true" max_bundle_size="64000"
max_bundle_timeout="30" use_incoming_packet_handler="true"
use_outgoing_packet_handler="true" down_thread="false" up_thread="false"
enable_bundling="true" start_port="7800" use_send_queues="false"
sock_conn_timeout="300" skip_suspected_members="true"/>
<MPING timeout="2000" num_initial_members="3" mcast_addr="229.6.7.8"
bind_addr="164.99.218.115" down_thread="false" up_thread="false"/>
<FD_SOCK down_thread="false" up_thread="false"/>
<pbcast.NAKACK max_xmit_size="60000" use_mcast_xmit="false" gc_lag="10"
retransmit_timeout="100,200,300,600,1200,2400,4800" down_thread="false" up_thread="false"
discard_delivered_msgs="true"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" down_thread="false"
up_thread="false" max_bytes="400000"/>
<pbcast.GMS print_local_addr="true" join_timeout="3000" down_thread="false" up_thread="false"
join_retry_timeout="2000" shun="true"/>
<FC max_credits="2000000" down_thread="false" up_thread="false" min_threshold="0.10"
max_block_time="1000"/>
</config>
Test 'config.txt' file
num_msgs=1000000 msg_size=1000 num_members=4 num_senders=4
Java
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)”
阿涂 发表于 2006-05-04 17:07 阅读( 1812) 评论( 1) 引用( 6) Java
JGroups and JGroup/ARM
JGroups : http://www.jgroups.org/javagroupsnew/docs/index.html
A Toolkit for Reliable Multicast Communication
JGroup/ARM: http://jgroup.sourceforge.net/index.html
The Jgroup Object Group System / The Autonomous Replication Management (ARM) framework
感觉这两个 framework 做的东西比较类似,并且名字也几乎一样,都是一个 Group Object 的概念。
相比之下, JGroups 实际应用的成功案例更多,大量的其他 OpenSource 软件都使用 JGroups 实现 J2EE Cluster 的状态同步。
http://www.jgroups.org/javagroupsnew/docs/success.html
并且加入了 JBoss 组织,由 JBoss 提供有偿技术支持。
这里有几篇关于 JGroups 评估相关的文章:
http://jmob.objectweb.org/JGroups.html
http://www.inria.fr/rrrt/rr-5336.html
阿涂 发表于 2006-05-04 16:14 阅读( 1615) 评论( 1) 引用( 6) Java
good article of mutilcast over tcp/ip
从网络以及操作系统层面讲解了 multcast 的原理以及编程模型,值得一看.
This HOWTO tries to cover most aspects related to multicast over TCP/IP networks. So, a lot of information within it is not Linux-specific (just in case you don't use GNU/Linux... yet). Multicast is currently an active area of research and, at the time of writing, many of the "standards" are merely drafts. Keep it in mind while reading the lines that follow.
http://www.tldp.org/HOWTO/Multicast-HOWTO.html
阿涂 发表于 2006-05-04 15:01 阅读( 1240) 评论( 0) 引用( 0) 技术
2006/05/01
good java site JavaPolis
just a recordJavaPolis 2005 talks (and DVD) are here...
Every week we'll release JavaPolis 2005 talks on our wiki, let the virtual JavaPolis begin !
阿涂 发表于 2006-05-01 10:21 阅读( 1130) 评论( 0) 引用( 0) Java
2006/04/30
关于 unicast, multicast, broadcast
1.unicast、broadcast、multicast在討論MBone之前,一定要先
了解unicast、broadcast、multicast三種傳輸方式的差異。以
Ethernet網路架構而言,封包(Packet)在同一個subnet中傳遞時
,以收方地址來判別該由那台主機接收;若在不同的subnet時,就
要透過路由器(Router)根據收方地址,把這個packet送往收方主
機所在的另一個subnet上。這就是Internet上最普遍、一對一方式
傳送的unicast。
另一類傳輸模式為一對多模式,分為broadcast和multicast 二種
。當broadcast時,同一subnet上所有主機都會收到broadcast
packet。但是broadcast packet會被subnet router擋下來,不會傳
送到另一個subnet,否則網路就會被broadcast packet癱瘓了。
multicast是一對一個群組(group)的傳輸模式,不同於
broadcast的是,同一subnet中只有參加multicast group的主機才
會收到封包,其他的主機就不會受到無謂的干擾,而且multicast
packet會透會mrouter(multicast router)的運作將封包送到另一
個subnet的multicast group。另一方面,multicast和broadcast相
同的特性是,不管接收封包的主機有幾台,都只有一個資料流,也
就是說,同一個subnet裏,不管接收主機的數量,所需的頻寬都是
一樣的。
2.IP multicasting:multicast究竟是如何辦到的呢? 在TCP/IP
的環境中,IP address被分為五大類,如圖一。
(圖一)
(有關Class E部份,目前仍有爭議,還在討論中尚未確定)
以第一個位元start bits的不同,可分為Class A、B、C、D、E
五大類。其中Class D的start bits為"1110",範圍從224.0.0.0~
239.255.255.255,這段位址不屬於任何主機,是特別保留給
multicast address。當一部主機要送multicast packet到某一個
group的主機時,他們之間要先選定一個閒置的Class D IP,並避免
和其他群組的multicast packet IP相同。然後這個multicast
packet送出時,網路上參與這個group的主機,除了接收屬於自己IP
的packet之外,也會接收自這個Class D IP的packet。於是達成了
multicast的目的了。
参考原文:http://www.ascc.sinica.edu.tw/nl/86/1321/03.txt
阿涂 发表于 2006-04-30 16:22 阅读( 1617) 评论( 1) 引用( 0) 技术
比较有用的 firefox 插件 firebug
http://www.joehewitt.com/software/firebug/
阿涂 发表于 2006-04-30 15:46 阅读( 1376) 评论( 3) 引用( 0) javascript
ibm提供的java高性能io -aio4j
What is Asynchronous IO for Java?
Asynchronous IO for JavaTM (AIO4J) is a package that provides the capability to perform input and output (IO) on sockets and files asynchronously -- that is, where the Java application can request the operation but can continue doing useful work while the underlying system performs the operation. The application is informed of the operation's completion later.
This package provides Java applications with capabilities that are now available from most operating systems at the "C" API layer, such as IO Completion Ports on Windows. AIO4J provides Java application programmers with access to these capabilities, but in a way that is very much in keeping with Java idioms and styles of programming.
AIO4J can be used as a replacement for classic synchronous IO and also as an alternative to the New IO package introduced in Java 1.4. AIO4J aims to give performance and scalability that is better than either of these other packages. In particular, AIO4J aims to help Java server applications address what has been called the "C10K problem": building server applications that serve 10,000 clients simultaneously with good responsiveness and performance. This is very difficult with Java synchronous IO because most systems cannot sustain 10,000 threads, and Java New IO does not perform well with such a load.
How does it work?
AIO4J provides a standard Java package of function, layered above a native library that interfaces with the underlying capabilities of the operating system.
The package provides facilities that support a range of programming styles, including Blocking, Polling and Callbacks as techniques for getting notifications of the completion of Read or Write operations.
For Callbacks, the application can control the number and the type of threads that are used.
原文:http://www.alphaworks.ibm.com/tech/aio4j
阿涂 发表于 2006-04-30 15:14 阅读( 1564) 评论( 2) 引用( 0) Java







