dht爬虫源码
1. python好学吗
记得刚学Python的时候,几乎所有人都说Python 简单易学,而对于编程零基础,只掌握Word和Excel的人来说,感觉真的好难。
学习之前网上的教材看了,Python的书也看了,包括《核心编程》,公开课也看了,包括莱斯大学和MIT的课。很多知识点,看的时候好像明白了,然后马上就忘,看了三四遍也记不住。
就算是多练习,多做题,很多题也是照着例题依样画葫芦就能做出来,改动一下就不明白了,感觉还是没有深入理解。
在网上看,到处都是自学几个月就很懂了然后找到满意工作的帖子,有没有人像我一样觉得很难呢?
有网友点评说:
Python语言本身是比较容易的,楼主说的难应该指programming本身。
不觉得非计算机专业出身就学不好编程,我就是学通信的,学Python全凭兴趣。平时用Python干各种脏活累活,数值计算、数据处理、复杂文本处理、数据库导入导出excel、网上抢票、Web数据抓取、消息推送、DHT网络爬虫、Kodi插件、Web自动化测试、网盘下载、云点播。甚至有次日记软件密码忘了,都是通过py+autoit暴力破解出来的。
我的win、debian、mac上面一般都会开一两个ipython,临时处理各类杂务。简单来说,Python现在就是我日常生活的一部分。我不是专业程序员,也没用Python做过什么大项目,只是每天享受Python带来的便捷与快乐。
楼主所说的不能深入理解,其实是不愿意花时间钻研。用了十几年Python,现在也要一直翻看官方文档和一些第三方mole的文档,不断把遇到的问题弄懂弄透,学习不就是这个过程么?
我觉得楼主对Python无爱,对编程无爱,那就没必要强迫自己填鸭式“学习”了。
另外一个建议,练习时尽量不要后在现有demo基础上改,从头开始写起,遇到问题一个个查清,这样才能学到东西。
接收到这个小伙伴的答案,我内心开始反思,其实他说得都对的3个点是:
1.其实本身我对编程是不热爱的,只是因为需要;
2.其实本身我是对Python更上层可以用来做什么是不清楚的,思维还是在机械的完成一个Python习题;
3.其实我本身对编程的难度是小悄了的,Python简单是相对于C、java等语言。
说到这里,不知道看到本文的小伙伴有几个有类似的心理映射,如果你是上面的状态,那你学习Python一定是难的。
下面我们来看看另外一位学习者的建议:
python是一门简单易学,容易理解,分分钟就可以掌握的语言,我也是学了大概一两个星期吧,就开始做项目了,嘻嘻!!!
这里有一个很严重的问题,,我在学python之前,做过3点的C#,一年的php和一年的java!
所以呢,我想说的是,如果你对编程不那么敏感,就需要时间来弥补了,那些什么书啊,公开课啊,我觉得都是辅助的,你要是不经历几个项目,怎么知道python为什么容易学,怎么知道python好理解,怎么知道python有哪些超级好用的框架,比如django,tonado之类的。
所以呀,编程没有捷径,你甭想通过看。。。就学会,写起来才是最重要的!
最终通过对学习Python这件事,我总结了几点关于学习Python的建议,希望跟大家一起分享:
1.编程语言是一回事,但更重要的是编程思想,不要把应试教育的思想带到这里面来,并不是所有的知识都能靠“五年高考三年模拟”来掌握;
2.自己找个想用程序解决的任务,然后自己边学边完成。
3.没有编程基础的人新学一门语言一定一定要有耐心,基础知识没有半年以上的学习和练习是很难彻底掌握的,千万不要图快,学的太快或许会有一时的成就感,但基础知识不扎实终将会成为你前进道路上的瓶颈,不仅学新的知识一知半解,工作时也会磕磕绊绊。
4.没有计算机基础,不管学什么语言都会有点吃力的,python语法比较简单的。
5.现在要做的就是把错误犯下100遍,那你就拿下这个Get了!
2. 如何在gluster的源码中添加自己的xlator
glusterfs中主线为xlator,几乎每一个大的功能点,或者性能,都可以以xlator形式参与进glusterfs中,那么xlator的开发就必不可少,所以,这里介绍一下简单的向glusterfs中增加xlator的方法,首先创建一个卷testvol
[root@CM addxlator]# mkdir /opt/test
[root@CM addxlator]# gluster volume create testvol 192.168.0.194:/opt/test force
volume create: testvol: success: please start the volume to access data
[root@CM addxlator]# gluster volume info all
Volume Name: testvol
Type: Distribute
Volume ID: f0ef2a09-09c0-4a84-aeb6-3f2e0aebf4c2
Status: Created
Number of Bricks: 1
Transport-type: tcp
Bricks:
Brick1: 192.168.0.194:/opt/test
[root@CM addxlator]#
[root@CM addxlator]# gluster volume start testvol force
volume start: testvol: success
[root@CM addxlator]#
创建成功后,可以查看volume file中的内容
cat /var/lib/glusterd/vols/testvol/testvol-fuse.vol
volume testvol-client-0
type protocol/client
option transport-type tcp
option remote-subvolume /opt/test
option remote-host 192.168.0.194
end-volume
volume testvol-dht
type cluster/distribute
subvolumes testvol-client-0
end-volume
volume testvol-write-behind
type performance/write-behind
subvolumes testvol-dht
end-volume
volume testvol-read-ahead
type performance/read-ahead
subvolumes testvol-write-behind
end-volume
volume testvol-io-cache
type performance/io-cache
subvolumes testvol-read-ahead
end-volume
volume testvol-quick-read
type performance/quick-read
subvolumes testvol-io-cache
end-volume
volume testvol-open-behind
type performance/open-behind
subvolumes testvol-quick-read
end-volume
volume testvol-md-cache
type performance/md-cache
subvolumes testvol-open-behind
end-volume
volume testvol
type debug/io-stats
option count-fop-hits off
option latency-measurement off
subvolumes testvol-md-cache
end-volume
这个配置为默认的配置,接下来需要将自己的xlator增加入该配置中,根据之前所提到过的xlator_dyload的过程,需要修改这个volume file,来增加xlator,修改配置如下:
volume testvol-client-0
type protocol/client
option transport-type tcp
option remote-subvolume /opt/test
option remote-host 192.168.0.194
end-volume
volume testvol-dht
type cluster/distribute
subvolumes testvol-client-0
end-volume
volume testvol-write-behind
type performance/write-behind
subvolumes testvol-dht
end-volume
volume testvol-read-ahead
type performance/read-ahead
subvolumes testvol-write-behind
end-volume
volume testvol-io-cache
type performance/io-cache
subvolumes testvol-read-ahead
end-volume
volume testvol-quick-read
type performance/quick-read
subvolumes testvol-io-cache
end-volume
volume testvol-open-behind
type performance/open-behind
subvolumes testvol-quick-read
end-volume
volume testvol-md-cache
type performance/md-cache
subvolumes testvol-open-behind
end-volume volume testvol-test
type debug/test
subvolumes testvol-md-cache
end-volume volume testvol
type debug/io-stats
option count-fop-hits off
option latency-measurement off
subvolumes testvol-test
end-volume
可以看到,配置中多了个testvol-test这么一层,接下来将glusterfs挂载至挂载点查看输出log
[root@CM addxlator]#
[root@CM addxlator]# mount -t glusterfs 192.168.0.194:testvol /media
[root@CM addxlator]#
查看gluster挂载到的挂载点对应的log输出信息
cat /usr/local/var/log/glusterfs/media.log
[2013-06-10 11:00:29.899440] I [glusterfsd.c:1878:main] 0-/usr/local/sbin/glusterfs: Started running /usr/local/sbin/glusterfs version 3git (/usr/local/sbin/glusterfs --volfile-id=testvol --volfile-server=192.168.0.194 /media)
[2013-06-10 11:00:29.903627] I [socket.c:3515:socket_init] 0-glusterfs: SSL support is NOT enabled
[2013-06-10 11:00:29.903823] I [socket.c:3530:socket_init] 0-glusterfs: using system polling thread
[2013-06-10 11:00:29.909423] E [test.c:54:init] 0-testvol-test: test translator loaded
[2013-06-10 11:00:29.909718] I [dht-shared.c:311:dht_init_regex] 0-testvol-dht: using regex rsync-hash-regex = ^\.(.+)\.[^.]+$
[2013-06-10 11:00:29.911047] I [socket.c:3515:socket_init] 0-testvol-client-0: SSL support is NOT enabled
[2013-06-10 11:00:29.911173] I [socket.c:3530:socket_init] 0-testvol-client-0: using system polling thread
[2013-06-10 11:00:29.911218] I [client.c:2236:notify] 0-testvol-client-0: parent translators are ready, attempting connect on transport
Final graph:
经过查看log,可以看到test模块中的打印输出, in test translator lookup
接下来查看描述一下外挂xlator的方式
首先现在glusterfs的源代码,编译以后,在本地也就存在了glusterfs的开发环境,为了开发调试方便,可暂不将xlator存于glusterfs工程中,这时可以编写一个Makefile
首先建立一个目录
mkdir addxlator_sample
cd addxlator_sample
Makefile中内容可如下:
#Add translator into glusterfs volume file
#Author Steven Liu
#E-mail [email protected]
#Blog: http://blog.fs-linux.org
TARGET = test.so
OBJECTS = test.o
GLUSTERFS_SRC = /opt/glusterfs
GLUSTERFS_LIB = /usr/local/lib
HOST_OS = HF_LINUX_HOST_OS
CFLAGS = -fPIC -Wall -O0 -g \
-DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(HOST_OS) \
-I$(GLUSTERFS_SRC) -I$(GLUSTERFS_SRC)/libglusterfs/src \
-I$(GLUSTERFS_SRC)/contrib/uuid
LDFLAGS = -shared -nostartfiles -L$(GLUSTERFS_LIB) -lglusterfs -lpthread
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)
clean:
rm -rf $(TARGET) $(OBJECTS)
Makefile编写完成之后,需要OBJECTS,这时需要编写test.c来保证编译通过,当然,test这个xlator也需要在这里生成
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#include "xlator.h"
#endif
#include <fnmatch.h>
#include <errno.h>
#include "glusterfs.h"
#include "xlator.h"
#include <stdarg.h>
#include "defaults.h"
#include "logging.h"
int test_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
inode_t *inode, struct iatt *buf,
dict_t *xdata, struct iatt *postparent)
{
STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, xdata,
postparent);
return 0;
}
static int test_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
gf_log(this->name, GF_LOG_ERROR, "in test translator lookup");
STACK_WIND (frame, test_lookup_cbk,
FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup,
loc, xdata);
return 0;
}
static int test_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
gf_log(this->name, GF_LOG_ERROR, "in test translator stat");
return 0;
}
int
reconfigure (xlator_t *this, dict_t *options)
{
return 0;
}
int
init (xlator_t *this)
{
struct ios_conf *conf = NULL;
int ret = -1;
gf_log (this->name, GF_LOG_ERROR, "test translator loaded");
if (!this)
return -1;
if (!this->children) {
gf_log (this->name, GF_LOG_ERROR,
"test translator requires atleast one subvolume");
return -1;
}
if (!this->parents) {
gf_log (this->name, GF_LOG_ERROR, "dangling volume. check volfile ");
}
conf = this->private;
this->private = conf;
ret = 0;
return ret;
}
void
fini (xlator_t *this)
{
struct ios_conf *conf = NULL;
if (!this)
return;
conf = this->private;
if (!conf)
return;
this->private = NULL;
GF_FREE(conf);
gf_log (this->name, GF_LOG_ERROR, "test translator unloaded");
return;
}
int
notify (xlator_t *this, int32_t event, void *data, ...)
{
default_notify (this, event, data);
return 0;
}
struct xlator_fops fops = {
.stat = test_stat,
.lookup = test_lookup,
};
struct xlator_cbks cbks = {
};
struct volume_options options[] = {
};
目前仅用于测试的xlator而已,所以自己定义了lookup与stat,还有lookup_cbk,其他的并未定义,全部走default,这个原理在之前已经提到过。
然后执行make既可生成对应的xlator文件
Makefile test.c test.o test.so
将test.so复制至/usr/local/lib/glusterfs/3git/xlator/debug中
然后执行glusterfs的客户端,mount至挂载节点,如果成功,可以查看log,整个过程成功矣~~!
转载
3. python好学吗
有网友点评说:
Python语言本身是比较容易的,楼主说的难应该指programming本身。
不觉得非计算机专业出身就学不好编程,我就是学通信的,学Python全凭兴趣。平时用Python干各种脏活累活,数值计算、数据处理、复杂文本处理、数据库导入导出excel、网上抢票、Web数据抓取、消息推送、DHT网络爬虫、Kodi插件、Web自动化测试、网盘下载、云点播。甚至有次日记软件密码忘了,都是通过py+autoit暴力破解出来的。
我的win、debian、mac上面一般都会开一两个ipython,临时处理各类杂务。简单来说,Python现在就是我日常生活的一部分。我不是专业程序员,也没用Python做过什么大项目,只是每天享受Python带来的便捷与快乐。
楼主所说的不能深入理解,其实是不愿意花时间钻研。用了十几年Python,现在也要一直翻看官方文档和一些第三方mole的文档,不断把遇到的问题弄懂弄透,学习不就是这个过程么?
我觉得楼主对Python无爱,对编程无爱,那就没必要强迫自己填鸭式“学习”了。
另外一个建议,练习时尽量不要后在现有demo基础上改,从头开始写起,遇到问题一个个查清,这样才能学到东西。
接收到这个小伙伴的答案,我内心开始反思,其实他说得都对的3个点是:
1.其实本身我对编程是不热爱的,只是因为需要;
2.其实本身我是对Python更上层可以用来做什么是不清楚的,思维还是在机械的完成一个Python习题;
3.其实我本身对编程的难度是小悄了的,Python简单是相对于C、Java等语言。
说到这里,不知道看到本文的小伙伴有几个有类似的心理映射,如果你是上面的状态,那你学习Python一定是难的。
下面我们来看看另外一位学习者的建议:
python是一门简单易学,容易理解,分分钟就可以掌握的语言,我也是学了大概一两个星期吧,就开始做项目了,嘻嘻!!!
这里有一个很严重的问题,,我在学python之前,做过3点的C#,一年的php和一年的java!
所以呢,我想说的是,如果你对编程不那么敏感,就需要时间来弥补了,那些什么书啊,公开课啊,我觉得都是辅助的,你要是不经历几个项目,怎么知道python为什么容易学,怎么知道python好理解,怎么知道python有哪些超级好用的框架,比如django,tonado之类的。
所以呀,编程没有捷径,你甭想通过看。。。就学会,写起来才是最重要的!
最终通过对学习Python这件事,我总结了几点关于学习Python的建议,希望跟大家一起分享:
1.编程语言是一回事,但更重要的是编程思想,不要把应试教育的思想带到这里面来,并不是所有的知识都能靠“五年高考三年模拟”来掌握;
2.自己找个想用程序解决的任务,然后自己边学边完成。
3.没有编程基础的人新学一门语言一定一定要有耐心,基础知识没有半年以上的学习和练习是很难彻底掌握的,千万不要图快,学的太快或许会有一时的成就感,但基础知识不扎实终将会成为你前进道路上的瓶颈,不仅学新的知识一知半解,工作时也会磕磕绊绊。
4.没有计算机基础,不管学什么语言都会有点吃力的,python语法比较简单的。
5.现在要做的就是把错误犯下100遍,那你就拿下这个Get了!
祝你学习Python之路愉快。
知乎网友任泉经典评论:
说Python简单的都是程序员或者半程序员,说其实还是很困难的都是有需求但并非依赖性的业余爱好者。
Python的简单,是相对于C++的简单,而不是相对于Word、Excel的简单。它再接近自然语言,也有语法,也有数据结构,也有编程思想,而这些对于“业务爱好者”来说就等于“难”。
想要不难也很容易,保证自己每天都会去使用它就好了,每天不管是看书学习也好,照着案例敲代码也好,针对需求写个小程序也好,一定要每天用,直到自己习惯语法,习惯数据结构,习惯编程思想为止,到那个时候,你就变成了半个程序员。
想以一周一两次,甚至更低的频率来学习编程,无论你内心多么热爱,无论这门语言多么简单,都是学不会的,更别谈学好了。
