2010-06-23 11:18:41
涉及的技术内容包括:ASM、ANSI C、.NET/C#、Python、Linux/Ubuntu 等。
记录读书笔记、生活点滴。关注基础理论和开发……
除特别标注外,所有文章均为作者原创,转载请注明出处。谢谢!

  查看 "推荐文章目录"。  


  研发中心长期招聘开发人员,详情请点击 "Linux/C, Python 职位"、 ".NET/C# 职位"。
  雨痕内部技术交流群,欢迎熟识的朋友参与。 将 添加为您的 MSN 联系人即可。
  为杜绝垃圾广告的侵扰,只有注册用户可以发表评论和留言。
  如果有什么问题,可以单击右侧图标给雨痕发消息。( 绿色: 在线; 灰色: 脱机)
浏览模式: 普通 | 列表

MongoDB: 6. Optimization

[ 2010-07-29 10:20:09 | 作者: yuhen ]
1. Profiler

MongoDB 自带 Profiler,可以非常方便地记录下所有耗时过长操作,以便于调优。
> db.setProfilingLevel(n)

n: 
   0: Off; 
   1: Log Slow Operations; 
   2: Log All Operations.

通常我们只关心 Slow Operation,Level 1 默认记录 >100ms 的操作,当然我们也可以自己调整 "db.setProfilingLevel(2, 300)"。
Profiler 信息保存在 system.profile (Capped Collection) 中。

准备 1000000 条数据测试一下。
>>> from pymongo import *
>>> from random import randint
...

阅读全文…

MongoDB: 5. Admin

[ 2010-07-25 03:12:56 | 作者: yuhen ]
Mongod 是 MongoDB 核心程序,通常情况下我们只需折腾该程序即可。

1. dbpath & port

默认数据存储路径是 /data/db,默认端口 27017,默认 HTTP 端口 28017。用 --dbpath 和 --port 改吧。
$ sudo ./mongod --dbpath /var/mongodb --port 1234

Sat Jul 24 22:58:50 MongoDB starting : pid=1683 port=1234 dbpath=/var/mongodb 64-bit

** NOTE: This is a development version (1.5.4) of MongoDB.
**       Not recommended for production.
...

阅读全文…

MongoDB: 4. Index

[ 2010-07-24 15:52:58 | 作者: yuhen ]
MongoDB 提供了多样性的索引支持。
> for (var i = 0; i < 30; i++) {
...     u = { name : "user" + i,
...           age : 20 + i,
...           contact : {
...              address : ["address1_" + i, "address2_" + i],
...              postcode : 100000 + i,
...           }
...     };
...     db.users.insert(u);
... }

索引信息被保存在 system.indexes 中,且默认总是为 _id 创建索引。
> show collections
system.indexes
...

阅读全文…

MongoDB: 3. Schema Design

[ 2010-07-22 10:36:03 | 作者: yuhen ]
1. Document-Oriented

MongoDB 是一种面向文档(document-oriented)的数据库,其内存储的是一种 JSON-like 结构化数据。尽管拥有和关系型数据库 Database/Table 类似的的 DB/Collection 概念,但同一 Collection 内的 Document 可以拥有不同的属性。

(注: 以下 > 提示符表示 mongo JS 代码,>>> 为 Python 代码)
> use blog
switched to db blog

> db.users.insert({name:"user1", age:15})
> db.users.insert({name:"user2", age:20, sex:1})

> db.users.find()
{ "_id" : ObjectId("4c479885089df9b53474170a"), 
...

阅读全文…

MongoDB: 2. Basic Usage

[ 2010-07-20 14:19:14 | 作者: yuhen ]
须安装 PyMongo (Documentation)。
$ sudo easy_install -U pymongo

(注: 以下 > 提示符表示 mongo JS 代码,>>> 为 Python 代码)

1. INSERT

使用 insert 插入文档。
> use blog
switched to db blog

> u = { name:"user1", age:23 }
{ "name" : "user1", "age" : 23 }

> db.users.insert(u)

> u2 = db.users.findOne({name:"user1"})
...

阅读全文…

MongoDB: 1. Database

[ 2010-07-20 09:19:19 | 作者: yuhen ]
mongo 是 MongoDB 自带的交互式 Javascript shell,用来对 Mongod 进行操作和管理的交互式环境。

使用 "./mongo --help" 可查看相关连接参数。
$ ./mongo --help

MongoDB shell version: 1.5.3

usage: ./mongo [options] [db address] [file names (ending in .js)]

db address can be:
  foo                   foo database on local machine
  192.169.0.5/foo       foo database on 192.168.0.5 machine
...

阅读全文…

IPython Magic Functions

[ 2010-07-19 22:03:24 | 作者: yuhen ]
将 IPython 用熟了,可以轻松在试验、编码、测试间 "无缝折腾"。[lol]
$ ipython

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. 
...

阅读全文…

Git Commands

[ 2010-07-18 16:42:25 | 作者: yuhen ]
1. 系统设置

通常情况下,我们只需简单设置用户信息和着色即可。
$ git config --global user.name "Q.yuhen"
$ git config --global user.email qyuhen@abc.com
$ git config --global color.ui true 

可以使用 "--list" 查看当前设置。
$ git config --list

2. 初始化

创建项目目录,然后执行 "git init" 初始化。这会在项目目录创建 ".git" 目录,即为元数据信息所在。
$ git init

通常我们还需要创建一个忽略配置文件 ".gitignore",并不是什么都需要加到代码仓库中的。

...

阅读全文…