日志分类:Linux与开源

Enabling systemd-style socket service written in Java

2013/03/24 | 13:33 | 分类:Linux与开源 | 标签: | 684次阅读

sd-daemon-java

Enabling systemd-style socket service written in Java
https://github.com/sswv/sd-daemon-java
Licensed under the GNU Lesser General Public License Copyright (c) 2012-2013, Jian Lin

How to use
Please read the example code in "src/java/org/linjian/sd_daemon_java/example", diff'ing the "Server" ones with the "ServerNew" ones.

Notice
This program is not yet mature. Only a part of functions in ServerSocket and ServerSocketChannel are covered, which may contain bugs. The simple examples run properly with this program. However, if you want to use it in more complicated or more crucial applications, this program should be improved.

Reference
systemd-style socket service in C: http://0pointer.de/blog/projects/socket-activation.html

Design of MPI-D logo

2012/11/16 | 14:02 | 分类:Linux与开源 | 标签: | 2,155次阅读

MPI-D will release soon!

MPI-D logo

Design of MPI D logo

Copyright (C) 2012 by the MPI-D team
Designed by Jian Lin (http://linjian.org).
Thanks to Xiaoyi Lu, Bing Wang, Fan Liang, and Juan Peng for advice.

The meaning of MPI-D logo

1. The white hollow lines in the logo are the abstract of DOTA model. The endpoints and crosspoints from left to right represent each level of D, O, T, and A respectively.
2. The logo consists of 2 parts, the left and the right, reflecting that the nature of DOTA model is a bipartite graph. The left part is in pure gray with the sense of flatness, while the right part is in gradient green with the sense of three-dimensional space. They represent that MPI-D can transmute insipid data into vibrant value, and also show MPI-D's recognition and practice on green computing.
3. The right part is a variant of the letter D that is the first letter of Data and DOTA. The D composes of 4 blocks, representing the 4 characteristics of data computing, that is, Dichotomic, Dynamic, Diversified and Data-centric. The top and bottom blocks of the D shaped like wings represent that MPI-D will help data computing to take off.
4. The left part composes of 3 blocks, representing the theoretical foundation of MPI-D: the 3 theorems of DOTA. The 3 blocks look like the wake of the flying D as well, enhancing the sense of speed.
5. The writing of MPI-D is in black, which is mature and contrasting. The use of the open source Linux Biolinum font with light serif is easily identifiable, and brings a relaxed atmosphere without losing rigorous.

MPI-D Logo 释义

1. 图形中的白色镂空线条是对 DOTA 模型的抽象,线条端点和交点由左至右,分别代表 D、O、T、A 各个层次。
2. 图形由左、右两部分构成,体现 DOTA 模型的本质是二分图。左侧为单一的、平面感的灰色,右侧为渐变的、立体感的绿色,表示 MPI-D 将平淡无奇数据变为生机盎然的价值,同时也代表 MPI-D 认同并践行绿色计算的理念。
3. 右侧绿色部分是字母 D 的变体,即 Data 和 DOTA 的首字母。D 字由 4 块图形构成,代表数据计算的 Dichotomic、Dynamic、Diversified 和 Data-centric 特征。D 字上方和下方的 2 块图形如同两翼,代表 MPI-D 令数据计算如虎添翼。
4. 左侧灰色部分由 3 块图形构成,代表 MPI-D 的理论基础——DOTA 三大定理。3 块图形如同 3 条尾迹,为腾飞的 D 字增加了速度感。
5. MPI-D 文字为黑色,成熟稳重、对比鲜明。使用带有平缓衬线的 Linux Biolinum 开源字体,可辨识度高,在带来轻松气氛的同时不失严谨。

References

[1] Xiaoyi Lu. Research on Key Issues of Professional Services in Cloud Computing. PhD dissertation, Graduate University of Chinese Academy of Sciences, 2012. (in Chinese)
[2] Xiaoyi Lu, Bing Wang, Li Zha, Zhiwei Xu. Can MPI Benefit Hadoop and MapReduce Applications? In Workshop SRMPDS 2011, Proceedings of the 40th International Conference on Parallel Processing (ICPP 2011), 2011.

Run Hadoop on Raspberry Pi

2012/11/15 | 16:37 | 分类:Linux与开源 | 标签: | 2,471次阅读

A post on serverfault said that running Hadoop on Raspberry Pi would be "incredibly bad". But how bad it would be? By the opportunity of another experiment, I set up a Hadoop standalone installation on my Raspberry Pi Model B (256 MB memory) and tested its performance. We know that the heap size of different components in Hadoop can be scaled. However, after several attempts, I found it difficult to restrict MapReduce, HDFS, and an example job within Raspberry Pi's memory and swap file. Therefore, I plugged a USB flash disk (8GB) and made it as a swap partition (NOTICE: Only for experiment. Frequent swapping in/out operations could damage flash memory).

The operating system is Debian wheezy (with hard-float ABI), Java environment is OpenJDK 6, and Hadoop version is 1.0.4. The native code loader and snappy compression library were compiled in x86, which are not runnable on Raspberry Pi, but this does not affect the normal running of Hadoop. I did not recompile these native libraries in order to save time.

I ran the wordcount example over 80KB text files (i.e. the files in Hadoop's conf directory). The result was really "incredibly bad". The job had run over 1 hour before it completed.

  1. User: pi
  2. Job Name: word count
  3. Job File: hdfs://raspberrypi21:54310/home/pi/hdfs/mapred/staging/pi/.staging/job_201211151333_0001/job.xml
  4. Submit Host: raspberrypi21
  5. Submit Host Address: raspberrypi21
  6. Job-ACLs: All users are allowed
  7. Job Setup: Successful
  8. Status: Succeeded
  9. Started at: Thu Nov 15 13:44:59 CST 2012
  10. Finished at: Thu Nov 15 14:49:00 CST 2012
  11. Finished in: 1hrs, 4mins, 1sec
  12. Job Cleanup: Successful

In contrast, MPI (MPICH2) has a relatively acceptable performance on Raspberry Pi. From the perspectives of the history and implementation, it is easy to understand. Of course, there should be possibility of memory optimization for running Hadoop on Raspberry Pi.

为什么会有 setuid?为什么不是别的机制?

2012/07/16 | 19:42 | 分类:Linux与开源 | 标签: | 5,981次阅读

  来我们组面试过的同学,如果在简历中写了“熟悉 Unix/Linux”之类的话,那么很可能被问到类似这样的问题:“为什么会有 setuid?为什么不是别的机制?”。前不久和徐老师讨论设计原则问题时又聊到了这个 setuid。应徐老师建议,写下这篇命题作文,说说我的理解。
  首先从 setuid 的应用场景谈起。很多教科书和网络文章讲 setuid 时都会拿 passwd 命令举例(据说老一辈人更喜欢举 mailbox 的例子,异曲同工)。我们抛开对已知实现方式的理解,假设需要重新设计,看看这个场景有哪些需求和解决方案。需求方面,一种典型理解是:要求用户 a 可以使用程序 φ 受控地操作用户 b 的文件 θ。所谓受控,是指满足一个操作约束集合 S。除此之外,用户 a 对用户 b 的其他文件没有任何特权。事实上这就是一个访问控制问题,前人已经总结了若干解决模型。完备的角色访问控制(RBAC)或许能够涵盖全部需求,只要系统或管理员为特定的业务提供特定的角色并严格控制会话;即便使用自主访问控制(DAC),只要实现得足够细粒度,也可以尽力满足上述需求,只是安全性保证略差。但以文件为主要客体抽象的 Unix 偏偏选择了一种粗粒度的 DAC——ugorwx。为什么要做出这种选择?这很可能与 Unix 的“简单(K.I.S.S.)”设计哲学密切相关。相比其他模型,ugorwx 对系统和应用作出最少的必要假设,在提供最基本安全性的同时保证了较小的存储和决策开销。单纯使用 ugorwx 模型已经能够涵盖大多数正常业务操作(与系统管理或实用工具操作相对)的访问控制共性需求。
  然而 ugorwx 不能满足 passwd 和 mailbox 那样的需求,因为它对 θ 的控制粒度太粗,允许 b 使用 φ 操作 θ,就意味着必须允许所有用户使用任意程序操作 θ,那么篡改他人密码、偷看他人邮件岂不易如反掌?于是,必须要有一种额外机制为 ugorwx 的简单性承担责任。现在假设要我们来设计这个额外机制,可以怎么干呢?万全之道可能是做一套基于规则的访问控制系统,在特定条件触发时执行——这显然不够简单。还可以给每个用户或文件挂一个访问控制列表(ACL),声明特权,但其实主体之间的特殊关系可以通过 group 约束,ACL 这种特殊化不但不够简单,还可能违背了 ugorwx 的设计初衷。那么,只能把目光集中到那个特殊的程序 φ 上。可以对它做一些手脚吗?其一,φ 只是一小类需要特殊处理的例外程序,程序本身是可以精心设计的,也就是说 φ 已经自包含了 S 和 θ 属性,无须对 S 和 θ 做专门处理。其二,既然 ugorwx 的设计将主体关系特殊性交由 group 处理,那么就有理由忽略各个 others 成员的特殊性,即忽略 a。其三,b 对 θ 的 owner 关系是 ugorwx 中已经存在的,φ 运行时访问 θ,可以获知这个信息。基于上述事实,一种最小开销的额外机制设计也就水到渠成:通过一个特殊的标志位标识特殊的程序 φ,并在进程中区分“真实 UID”与“有效 UID”的概念——这基本就是 setuid 了。论功能,setuid 的确不够完备,但上述分析说明这并不是大问题,至少已经可以应对 passwd 和 mailbox 场景了。
  事实上,Unix 设计哲学对各个属性的取舍早已得到总结。Richard Gabriel 的经典名篇 The Rise of “Worse is Better”中将其归纳为“新泽西方法”,即:简单性是系统设计的第一要素,实现的简单比接口的简单更重要;任何值得注意的方面都要求正确性,但为了简单性,正确性可以轻微让步;设计不能过于不一致,但为了简单性,一致性可以有所牺牲;完备性应该覆盖实践中许多重要的情况,但只要简单性受到危害,完备性必须作出牺牲。对照来看,ugorwx 是一种接口和实现都很简单的设计;ugorwx 与 setuid 提供的安全级别(正确性)有限,但对通用操作系统来说已经足够;setuid 以牺牲接口一致性为代价确保了 ugorwx 机制在多数情况下的简单性,同时本身的实现也保持了尽量简单;setuid 不具有 RBAC 那样的完备性,但已经能够应对系统管理或实用工具的等常见的重要场景。
  最后,我们向历史求证一下 setuid 的来源。Wikipedia 给出的答案并不令人惊讶,setuid 的创造者正是 Dennis Ritchie 大神,当时的一篇专利(US4135240 - Protection of data file contents)记录了他的设计思想。在这篇如同学术论文的专利中,Ritchie 确实把简单性作为了 setuid 的主要出发点和创新点。专利风格诚恳,不但给出了 setuid 的设计方案和应用示例,同时也承认了它在功能上的不足。根据 Wikipedia 上给出的引文,AT&T 出于“不值得收取许可费用”的考虑,将该专利释放到了公有领域,任由开发者使用,这也使得 setuid 在多种衍生系统中发扬光大,流传至今。
  当然,对于这种开放性问题,每个人都可能有自己的答案,本文观点也只是作者的个人理解。不过如果你下次面试时遇到了诸如“为什么会有 ioctl”之类的问题,不妨从设计哲学角度考虑一下。

Raspberry Pi 到手

2012/06/30 | 23:06 | 分类:Linux与开源 | 标签: | 7,392次阅读

  我五月初订购的 Raspberry Pi 到手了,比预计时间早一些。
  二月底 Raspberry Pi 正式发布时,idealee 同学专门给我发邮件说过它。我当时没太在意,因为大学时做竞赛项目也用过一些小主板、小 PC,包括 VIA Pico-ITXeBox,故而对 Raspberry Pi 的“小”没什么感觉。但五一时偶然在所里见到一块 Raspberry Pi,试用了一下,又听了同学神侃,我发现 Raspberry Pi 还是有一些优势的,包括价格、开放性、可折腾性等。加之它有慈善组织背景,于是决定订购一块,研究加收藏。
Raspberry Pi 到手
  到手之后简单测试,感觉 Raspberry Pi 的性能还是符合我的预期的。官方提供的映像使用起来基本没有障碍,我手头的外设也都工作良好。专门试了一下 GPIO,只需要读写 /sys 文件系统就可以实现控制交互。只有一点不爽的:Raspberry Pi 的视频输出接口是 HDMI 和 Composite RCA(“AV”的“V”),而我周围的显示器都是 VGA 的,不光没有 HDMI,连 DVI 都没有,只能使用 HDMI-VGA 转接头。一个转接头的价格快赶上 Raspberry Pi 本身了,好在实验室某果粉手里有一个,借来先用。通过廉价的山寨 USB 视频采集卡接入 Composite RCA 信号也是一个办法,但这又不是玩 FC,PAL/NTSC 那点分辨率看看视频还行,操作终端和桌面可能会是煎熬。(这句话反过来说似乎也对?)
  顺便聊聊相关的产品。我前不久关注过 Arduino,因为连续几期《无线电》杂志几乎被它占领了。最初看到 Raspberry Pi 上那两排针脚时,我曾期望它能够完全涵盖 Arduino 的能力。不过查看相关资料后发现,Raspberry Pi 并没有侵占 Arduino 市场的意思。它只有 8 个非 0 即 1 的 GPIO,其余针脚是 UART、I2C、SPI 等接口,而非板载 ADC、DAC。这也好,EE 和 CS 本来就是有分工、有合作(如 Ponte)。
  最近另一款吸引眼球的小设备是 MK802 Android 4.0 Mini PC,它基于 Allwinner A10 解决方案,主要面向家庭娱乐市场。不考虑开放性等理想因素,对于非折腾型用户,MK802 的性价比可能比 Raspberry Pi 更高一些。当然,Android 系的东西要想折腾都是有可能的,CSK 同学几天前就给出了一个例子@lonepig 同学根据 Android 市场现状估计,MK802 这类产品还有降价空间。
  后续仍然关注 Raspberry Pi 的 26 根针脚,以及 DSI、CSI 接口的潜力。

页面: 上页(较新) 1 2 3 4 5 6 7 8 下页(较旧)