发现我是个懒得写blog的人 (随便说说)
发布于 2008-07-07 22:40 阅读:69679 评论:0 标签: 生活 学习

    发现,我是个懒得写blog的人。

    发现,网站的流量越来越少了,原因是搜索引擎来的流量少了,那为什么从搜索引擎来的流量少了呢,是因为我最近更新的blog文章少了,那为什么我最近更新的blog文章少了呢,是因为工作时间长了,让我没激情了?有可能。

    尽管在不断的学习积累,但感觉还是不够,也许是给自己的压力不够大,或是惰性来了。

    觉得应该再把时间抓紧点。解决一下效率问题,再做点为未来有必要做的事。

展开全文  
收起全文  
memcached英文文档学习 (C/C++学习)
发布于 2007-12-04 17:58 阅读:65356 评论:1 标签: Linux memcached 学习 英文

      今天看了memcached wiki的FAQ,觉得有几句话对了解memcached很有作用,与大家共享一下。

      服务器的内存如何分配问题:

以下是引用片段:
Because a 32-bit process can only address 4GB of virtual memory (usually significantly less, depending on your operating system), if you have a 32-bit server with 4-64GB of memory using PAE you can just run multiple processes on the machine, each using 2 or 3GB of memory.

     memcached之get过程,看点在于client/server的hash key处理:

以下是引用片段:
When doing a memcached lookup, first the client hashes the key against the whole list of servers. Once it has chosen a server, the client then sends its request, and the server does an internal hash key lookup for the actual item data.

      client/server的hash key算法差异:

以下是引用片段:
Different client implementations store data into memcached differently (perl Storable, php serialize, java hibernate, JSON, etc). Some clients also implement the hashing algorithm differently. The server is always the same however.

      当一个memcached down后的情况:

以下是引用片段:
 Remove dead nodes from your list. Be very careful! With default clients adding or removing servers will invalidate all of your cache! Since the list of servers to hash against has changed, most of your keys will likely hash to different servers. It's like restarting all of your nodes at the same time.

      key/value大小的说明:

以下是引用片段:
 Keys are restricted to 250 characters. Stored data cannot exceed 1 megabyte in size, since that is the largest typical slab size.

      数据存储的处理方式:

以下是引用片段:
 At first memcached did just use malloc/free for everything. However this does not play very well with OS memory managers. You get fragmentation, and your OS ends up spending more time trying to find contiguous blocks of memory to feed malloc() than it does running the memcached process.

      如何处理数据过期的问题:

以下是引用片段:
 When do expired cached items get deleted from the cache?

 memcached uses a lazy expiration, which means it uses no extra cpu
 expiring items. When an item is requested (a get request) it checks
 the expiration time to see if the item is still valid before returning
 it to the client.

 Similarly when adding a new item to the cache, if the cache is full,
 it will look at for expired items to replace before replacing the
 least used items in the cache.

      尤其是对数据过期的处理让偶意外,虽然省CPU,但很浪费空间。

       下面是几个常用的链接:

以下是引用片段:
 memcached'home
http://danga.com/memcached/

memcached'wiki
http://www.socialtext.net/memcached/index.cgi

memcached'faq
http://www.socialtext.net/memcached/index.cgi?faq

memcached'Protocol
http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt

memcached'consistent hashing
http://www.last.fm/user/RJ/journal/2007/04/10/392555/

展开全文  
收起全文  
php的异常处理基础学习 (PHP心得)
发布于 2007-09-09 18:33 阅读:9596 评论:2 标签: php 学习 异常

  一直以来对PHP5没怎么好好学习,属于那种用着的时候,查手册Google资料的那种人。前天看见同事的程序满眼的try,throw,catch,立马汗颜。不禁为自己在这方面的知识深深自责一下

  今天挤出点时间学习了这个东西。参考了一下文档:
  1:PHP 15:异常
  2:用实例分析PHP5异常处理,一看就懂
  3:PHP 5.0异常处理机制深度探索
  4:PHP5的异常处理机制

  PHP5内建的异常类需要有以下成员方法:

__construct() 构造函数,需要一个出错信息和一个可选的整型错误标记作参数
getMessage() 取得出错信息
getCode()
出错的代码
getFile() 异常发生的文件
getLine() 异常发生的行数
getTrace() 跟踪异常每一步传递的路线,存入数组,返回该数组
getTraceAsString()

和getTrace()功能一样,但可以将数组中的元素转成字符串并按一定格式输出

 __toString()  允许简单的显示Exception对象,并且给出所有以上方法给出的信息。

  Haohappy有几句话说的很好,PHP的异常机制可以满足我们如下的4点需求:

以下是引用片段:

1.允许一个方法给出一个出错标记给客户代码
2.提供程序错误的详细信息
3.让你同时判断多个出错条件,将你的错误报告和程序处理流程分开。
4.返回值必须是独立的类型,不会与正常返回的类型相混淆

  写了点程序练习一下:

以下是代码片段:

$a = 20;

// 使用常规catch的例子
try
{
  if($a == 1)
  {
    throw new Exception("I am 1", 1);
  }
  elseif ($a == 2)
  {
    throw new Exception("I am 2", 3);
  }
  elseif ($a == 3)
  {
    throw new Exception("I am 3", 3);
  }
  elseif ($a == 4)
  {
    throw new Exception("I am 4", 4);
  }
  else
  {
    throw new Exception("Who am I ?", 0);
  }
}
catch (Exception $e)
{
  if($e->getCode() == 1)
  {
    echo "1 : ".$e;
  }
  elseif ($e->getCode() == 2)
  {
    echo "2 : ".$e;
  }
  elseif ($e->getCode() == 3)
  {
    echo "3 : ".$e;
  }
  elseif ($e->getCode() == 4)
  {
    echo "4 : ".$e;
  }
  else
  {
    echo "0 : ".$e;
  }
}

echo "


";

// 使用不同的扩展异常类的例子
class A extends Exception{};
class B extends Exception{};

try
{
 if($a == 1)
  {
    throw new A("I am A", 1);
  }
  elseif ($a == 2)
  {
    throw new B("I am B", 2);
  }
  else
  {
    throw new Exception("Who am I ?", 0);
  }
}
catch (A $e)
{
  echo "1 : ".$e;
}
catch (B $e)
{
  echo "2 : ".$e;
}
catch (Exception $e)
{
  echo "0 : ".$e;
}

?>

  输出如下:

以下是引用片段:

0 : exception 'Exception' with message 'Who am I ?' in D:\WebPHP\WWW\new\test.php:24 Stack trace: #0 {main}


0 : exception 'Exception' with message 'Who am I ?' in D:\WebPHP\WWW\new\test.php:69 Stack trace: #0 {main}

展开全文  
收起全文