1. Algorithm 每周一道算法题
本周算法题为H 指数
本题的难点首先是要理解题目意思,题目要求的是至少有 H 篇论文的引用次数都大于等于 H,然后很自然的能想到一种方法,就是对论文引用次数进行排序,排序后从后往前遍历,当 count > 当前论文引用次数,返回 count 即可,还有第二种解决方案,该方案按照论文引用次数创建数组,当引用次数大于原数组长度,就当作最后一篇引用次数加 1,这样新数组就表示论文引用次数从 1 到 len 的论文篇数,从后往前遍历,计数 count,当 count 大于 i 时(即 H 指数大于当前论文引用次数),此时 count 就为结果,返回即可
2. Review 阅读一篇英文文章
本周继续阅读The C10K problem
- Serve many clients with each server thread, and use asynchronous I/O
每个服务端线程同时为多个客户端提供服务,并且使用异步 IO
This has not yet become popular in Unix, probably because few operating systems support asynchronous I/O, also possibly because it (like nonblocking I/O) requires rethinking your application. Under standard Unix, asynchronous I/O is provided by the aio_ interface (scroll down from that link to "Asynchronous input and output"), which associates a signal and value with each I/O operation. Signals and their values are queued and delivered efficiently to the user process. This is from the POSIX 1003.1b realtime extensions, and is also in the Single Unix Specification, version 2.
在 Unix 中异步 IO 还并未变得流行,可能是因为很少有操作系统支持异步 IO,并且可能因为异步 IO(像非阻塞 IO 一样)需要重新思考应用程序。在标准 Unix 中,异步 IO 通过 aio 接口提供(从该链接中找到"Asynchronous input and output")。每个 IO 操作都与一个信号和值相关联。信号和值被有效的排队并被发送到用户进程。这是来自POSIX 1003.1b实时扩展,并且也包含在Single Unix规范的第二版中。
AIO is normally used with edge-triggered completion notification, i.e. a signal is queued when the operation is complete. (It can also be used with level triggered completion notification by calling aio_suspend(), though I suspect few people do this.)、
AIO 通常与边缘触发完成信号一起使用,比如当操作完成时信号被排队(虽然也可以通过调用aio_suspend()来使用水平触发的完成通知,但我猜想很少有人这样做)。
glibc 2.1 and later provide a generic implementation written for standards compliance rather than performance.
glibc 2.1 以及更高版本提供了一个通用的实现,该实现是为了符合标准而不是性能编写的。
Ben LaHaise's implementation for Linux AIO was merged into the main Linux kernel as of 2.5.32. It doesn't use kernel threads, and has a very efficient underlying api, but (as of 2.6.0-test2) doesn't yet support sockets. (There is also an AIO patch for the 2.4 kernels, but the 2.5/2.6 implementation is somewhat different.) More info:
Ben LaHaise 为 Linux 实现的 AIO 被合并到 2.5.32 版本主线 Linux 内核中。它不使用内核线程,并且有非常高效的底层 API,但是(截止 2.6.0-test 版本)尚未支持套接字。(2.4 内核也有一个 AIO 补丁,但是 2.5/2.6 实现略有不同),更多信息参见下面文章:
- The page "Kernel Asynchronous I/O (AIO) Support for Linux" which tries to tie together all info about the 2.6 kernel's implementation of AIO (posted 16 Sept 2003)
- Round 3: aio vs /dev/epoll by Benjamin C.R. LaHaise (presented at 2002 OLS)
- Asynchronous I/O Suport in Linux 2.5, by Bhattacharya, Pratt, Pulaverty, and Morgan, IBM; presented at OLS '2003
- Design Notes on Asynchronous I/O (aio) for Linux by Suparna Bhattacharya -- compares Ben's AIO with SGI's KAIO and a few other AIO projects
- Linux AIO home page - Ben's preliminary patches, mailing list, etc.
- linux-aio mailing list archives
- libaio-oracle - library implementing standard Posix AIO on top of libaio. First mentioned by Joel Becker on 18 Apr 2003.
Suparna also suggests having a look at the the DAFS API's approach to AIO.
Suparna 也建议查看DAFS API对AIO的方法。
Red Hat AS and Suse SLES both provide a high-performance implementation on the 2.4 kernel; it is related to, but not completely identical to, the 2.6 kernel implementation.
Red Hat AS和Suse SLES都在2.4内核上提供了高性能的实现;它与2.6内核的实现有关,但不完全相同。
In February 2006, a new attempt is being made to provide network AIO; see the note above about Evgeniy Polyakov's kevent-based AIO.
在 2006 年 2 月,正在尝试提供一种新的网络 AIO,参见 Evgeniy Polyakov 的基于kevent的AIO相关的上述说明。
In 1999, SGI implemented high-speed AIO for Linux. As of version 1.1, it's said to work well with both disk I/O and sockets. It seems to use kernel threads. It is still useful for people who can't wait for Ben's AIO to support sockets.
1999年,SGI为Linux实现了高速AIO。从1.1版本开始,它据说对磁盘I/O和套接字都工作良好。它似乎使用了内核线程。对于那些不能等待Ben的AIO支持套接字的用户来说,它仍然很有用。
The O'Reilly book POSIX.4: Programming for the Real World is said to include a good introduction to aio.
据说O'Reilly的书《POSIX.4: Programming for the Real World》对aio有很好的介绍。
A tutorial for the earlier, nonstandard, aio implementation on Solaris is online at Sunsite. It's probably worth a look, but keep in mind you'll need to mentally convert "aioread" to "aio_read", etc.
关于Solaris上早期的非标准aio实现,有一个在线教程可在Sunsite上找到。它可能值得一看,但请记住,您需要将"aioread"转换为"aio_read"等。
Note that AIO doesn't provide a way to open files without blocking for disk I/O; if you care about the sleep caused by opening a disk file, Linus suggests you should simply do the open() in a different thread rather than wishing for an aio_open() system call.
请注意,AIO并没有提供一种无需阻塞磁盘I/O就能打开文件的方法;如果您关心由打开磁盘文件引起的延迟,Linus建议您应该在不同的线程中执行open(),而不是期望有一个aio_open()系统调用。
Under Windows, asynchronous I/O is associated with the terms "Overlapped I/O" and IOCP or "I/O Completion Port". Microsoft's IOCP combines techniques from the prior art like asynchronous I/O (like aio_write) and queued completion notification (like when using the aio_sigevent field with aio_write) with a new idea of holding back some requests to try to keep the number of running threads associated with a single IOCP constant. For more information, see Inside I/O Completion Ports by Mark Russinovich at sysinternals.com, Jeffrey Richter's book "Programming Server-Side Applications for Microsoft Windows 2000" (Amazon, MSPress), U.S. patent #06223207, or MSDN.
在 Windows 系统中,异步 I/O 通常与 "Overlapped I/O" 和 IOCP 或 "I/O Completion Port" 相关。微软的IOCP结合了异步 I/O(比如 aio_write)和队列完成通知(比如使用 aio_write 的 aio_sigevent 字段)等先前技术,并引入了一种新的思路,即保留一些请求以尝试保持与单个 IOCP 关联的运行线程数恒定。更多信息,请参阅sysinternals.com上Mark Russinovich 的《Inside I/O Completion Ports》(链接),Jeffrey Richter 的书《Programming Server-Side Applications for Microsoft Windows 2000》(Amazon链接、MSPress链接),美国专利号06223207,或MSDN链接。
3. Techniques/Tips 分享一个小技巧
本周在发布项目出现了问题,问题根本原因是 mybatis gennerator 生成的 xml 被修改后重新执行时被覆盖了,导致修改全部丢失,从而在发布时出现异常,进而导致回滚
该问题的根源在于对自动生成的文件做了修改,一定要牢记对 mybatis generator 生成的文件一定不能做任何修改,哪怕一个标点符号都不能改,一旦有任何改动,都应该单开一个 ext 文件手写实现,这样才能保证不出问题,工具是好工具,但是使用不当就会造成意想不到的后果。
4. Share 分享一个观点
最近也临近过年了,感觉学习的劲头疲软了很多,想做的事,想学的东西很多,但都很拖延,不想立刻行动,我没有比较好的办法解决这个问题,只能是周末一有空就到图书馆,这里学习氛围浓厚些,能稍有改善,但是跟前面也没得比,心静不下来,大家有什么好的调整方法吗?