Recently in development Category

性能问题

| No Comments | No TrackBacks

记点笔记:High-Performance Server Architecture

性能问题一般因以下四个原因而起:

  1. Data copies(数据复制)
  2. Context switches(上下文切换)
  3. Memory allocation(内存分配)
  4. Lock contention(锁争用)

为避免Data copies,作者使用的方法是间接使用和通过buffer descriptor来代替buffer pointer,每一个buffer descriptor由以下部分构成:

  • A pointer and length for the whole buffer. 一个指向整个buffer的指针和大小。
  • A pointer and length or offset and length for the part of the buffer that's actually used. 一个指向buffer实际使用部分的指针和大小或偏移量及大小。
  • Forward and back pointers to other descriptors in a list. 指向其他描述符的向前及向后的指针列表。
  • a reference count. 一个引用计数。
但是作者并不推荐在所有情况下都这样用做,因为在描述符的链表中穿行是非常痛苦的,这个做法虽然提高了性能但是却比data copies更恶。最好的做法是标记所有较大的对象,比如说数据块,确保他们像上述那样被独立分配,这样他们就不会被复制了。另外也说了一些因避免复制而做出的更坏的事情,比如强制一个上下文切换,分解一个大的IO请求。为避免Data copies,第一个要关心的应该是如何避免额外的操作。

最近写的一个东东要用python25和python-ldap,但是使用的那台主机是python23、ldap2.2.x和python-ldap2.0.1。安装了一个python25,python-ldap是2.3.8,编译失败,openldap2.2太老了,python-ldap2.3.8不向下兼容了。

那我就用python-ldap2.0.x,这个版本已经不提供下载了,从sf.net的cvs上拉了一份2.0.11的版本,这次倒是编过去了。用的时候出问题了

*** glibc detected *** free(): invalid pointer: 0xb7f60728 ***
Aborted

查来查去有三个文章有说这种情况

主要原因是PyMem_DEL的调用已经不被推荐了,应该用PyObject_Del。所以要对两个C文件做一些改动。

sed -i.orig 's/PyMem_DEL/PyObject_Del/g' Modules/LDAPObject.c 
sed -i.orig 's/PyMem_DEL/PyObject_Del/g' Modules/ldapcontrol.c 

然后再build,install就OK了

django m2m自包含

| No Comments | No TrackBacks
设计一个group,可以包含user也可以包含group。user和group都可以被多个group包含。
class Group(models.Model):
    users = models.ManyToManyField(User)
    groups = models.ManyToManyField('self')
update: ManyToMany对象有一个symmetrical的参数,当为True时的意思是对象间有互相拥有的关系,是双向的,反之为False时就是单向的。

django admin的变化

| No Comments | No TrackBacks
今天从django的svn拉出一份出来写点东东,写好了models,runserver查看admin的时候却出现了如下提示
You don't have permission to edit anything
翻了一下文档,发现已经0.97的时候变化了很多的东东。最后说明是要这样写。
urls.py里写入
from django.contrib import admin
admin.autodiscover()

settings.py中的INSTALLED_APPS部分加入

 INSTALLED_APPS = (
    'django.contrib.admin')

models.py的最后要写上

from django.contrib import admin
admin.site.register(MODELNAME)

这样才算是OK。
update: django 1.0之后的应该把上面这一段放到admin.py里去,而且要把以前写在models.py里的class admin部分也放到admin.py例子如下:

from django.contrib import admin
from models import Module
class ModuleAdmin(admin.ModelAdmin):
	list_display = ['name','manager','isdpool']
	filter_horizontal = ['host']
admin.site.register(Module,ModuleAdmin)

有个django的东东要写一个daemon来处理,这样就要在daemon script里初始化一个django environment,还好django提供了一个东东来设置这个environment.

import sys
sys.path.append('/home/guixing/Sites') #先要把自己的项目目录加入path
from django.core.management import setup_environ #这是重头戏,全靠它了
from myproject import settings #介绍自已人
setup_environ(settings) #安排自己人
#干活去吧

想干什么就干什么了,完全一样了。

最近在读C陷阱与缺陷,正好有朋友问到了在写Shell Script时要注意哪些东东。总结一下:
  • 注意空格
    • 有空格:在条件语句(if while until)中注意方括号与判定语句之间有空格
    • 没有空格:在赋值语句(=)等号两边是没有空格格的
其他的想起来了再写吧。

刚才在twitter上听到做完Project要写Pseudocode,不知道是什么东东,快快的去查了一下,才知道是要抛开LANG来写逻辑部分。

比如Hello World可以在pseudocode中这样写

output hello world

感觉上Apple Script应该是同一类的东东,但是能干活。

About this Archive

This page is an archive of recent entries in the development category.

arch is the previous category.

diary excerpt is the next category.

Find recent content on the main index or look in the archives to find all content.