【资源不友好代码】

from pyltp import *

d_dir = '/usr/local/ltp_data_v3.4.0/'

def gen_one_sentence_part(paragraph):
one_piece_split = [',', ',', '?', '?', '。', '.']
for i in one_piece_split:
paragraph = paragraph.split(i)[0]
return paragraph def gen_segmentor_words(paragraph):
# 分词 其他分析依赖于该数据
sentence = SentenceSplitter.split(paragraph)[0]
segmentor = Segmentor()
s = '%s%s' % (d_dir, "cws.model")
segmentor.load(s)
words = segmentor.segment(sentence)
del sentence, segmentor
return words def gen_postagger(words):
# 词性标注
postagger = Postagger()
s = '%s%s' % (d_dir, "pos.model")
postagger.load(s)
postags = postagger.postag(words)
del postagger
return postags ori_f = 'list_b_only_title.txt'
r_f = '%s%s' % (ori_f, '.del_ns.txt')
res = {}
with open(ori_f, 'r', encoding='utf8') as fo:
for i in fo:
p = i.replace('\n', '').replace('"', '')
p = gen_one_sentence_part(p)
words = gen_segmentor_words(p)
res[p] = gen_postagger(words) 【释放模型 model.release()】 free -g
在启动该脚本的前后内存与交换分区 root@hadoop1 tmp]# date
2017年 12月 14日 星期四 15:10:43 CST
[root@hadoop1 tmp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15           0          14           0           0          14
Swap:             7           0           6
[root@hadoop1 tmp]# date
2017年 12月 14日 星期四 15:10:54 CST
[root@hadoop1 tmp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15          13           0           0           0           1
Swap:             7           0           6
[root@hadoop1 tmp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15          14           0           0           0           0
Swap:             7           0           6
[root@hadoop1 tmp]# date
2017年 12月 14日 星期四 15:11:01 CST
[root@hadoop1 tmp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15          15           0           0           0           0
Swap:             7           1           6
[root@hadoop1 tmp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15          15           0           0           0           0
Swap:             7           2           5
[root@hadoop1 tmp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15          15           0           0           0           0
Swap:             7           2           5
[root@hadoop1 tmp]# [root@hadoop1 nlp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15           0          14           0           0          14
Swap:             7           0           6
[root@hadoop1 nlp]# dd if=/dev/zero of=/home/swap_xl bs=1024 count=1024*1024*4
dd: 无效的数字"1024*1024*4"
[root@hadoop1 nlp]# dd if=/dev/zero of=/home/swap_xl bs=1024 count=80^C
[root@hadoop1 nlp]# ^C
[root@hadoop1 nlp]# ^C
[root@hadoop1 nlp]# dd if=/dev/zero of=/home/swap_xl bs=1024 count=10485760
记录了10485760+0 的读入
记录了10485760+0 的写出
10737418240字节(11 GB)已复制,55.8535 秒,192 MB/秒
[root@hadoop1 nlp]# /sbin/mkswap /home/swap_xl
正在设置交换空间版本 1,大小 = 10485756 KiB
无标签,UUID=5121c17c-6664-40d3-a310-e79b24d7c6b1
[root@hadoop1 nlp]# /sbin/swapon /home/swap_xl
swapon: /home/swap_xl:不安全的权限 0644,建议使用 0600。
[root@hadoop1 nlp]# xlfg
              total        used        free      shared  buff/cache   available
Mem:             15           0           4           0          10          14
Swap:            17           0          16
[root@hadoop1 nlp]#

在SWAP空间不够用的情况下,如何手工添加SWAP空间?以下的操作都要在root用户下进行:
首先先建立一个分区,采用dd命令比如
dd if=/dev/zero of=/home/swap bs=1024 count=1024*1024
这样就会创建/home/swap这么一个分区文件。文件的大小是512000个block,一般情况下1个block为1K,所以这里空间是512M。接着再把这个分区变成swap分区。
/sbin/mkswap /home/swap
再接着使用这个swap分区。使其成为有效状态。
/sbin/swapon /home/swap
现在再用free -m命令查看一下内存和swap分区大小,就发现增加了512M的空间了。不过当计算机重启了以后,发现swap还是原来那么大,新的swap没有自动启动,还要手动启动。那我们需要修改/etc/fstab文件,增加如下一行
/home/swap swap swap defaults 0 0
你就会发现你的机器自动启动以后swap空间也增大了。

dd if=/dev/zero of=/home/swap_xl bs=1024 count=10485760
/sbin/mkswap /home/swap_xl
/sbin/swapon /home/swap_xl

[root@hadoop1 tmp]# dd  --help
用法:dd [操作数] ...
 或:dd 选项
Copy a file, converting and formatting according to the operands.

bs=BYTES        read and write up to BYTES bytes at a time
  cbs=BYTES       convert BYTES bytes at a time
  conv=CONVS      convert the file as per the comma separated symbol list
  count=N         copy only N input blocks
  ibs=BYTES       read up to BYTES bytes at a time (default: 512)
  if=FILE         read from FILE instead of stdin
  iflag=FLAGS     read as per the comma separated symbol list
  obs=BYTES       write BYTES bytes at a time (default: 512)
  of=FILE         write to FILE instead of stdout
  oflag=FLAGS     write as per the comma separated symbol list
  seek=N          skip N obs-sized blocks at start of output
  skip=N          skip N ibs-sized blocks at start of input
  status=LEVEL    The LEVEL of information to print to stderr;
                  'none' suppresses everything but error messages,
                  'noxfer' suppresses the final transfer statistics,
                  'progress' shows periodic transfer statistics

N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.

Each CONV symbol may be:

ascii     from EBCDIC to ASCII
  ebcdic    from ASCII to EBCDIC
  ibm       from ASCII to alternate EBCDIC
  block     pad newline-terminated records with spaces to cbs-size
  unblock   replace trailing spaces in cbs-size records with newline
  lcase     change upper case to lower case
  ucase     change lower case to upper case
  sparse    try to seek rather than write the output for NUL input blocks
  swab      swap every pair of input bytes
  sync      pad every input block with NULs to ibs-size; when used
            with block or unblock, pad with spaces rather than NULs
  excl  fail if the output file already exists
  nocreat do not create the output file
  notrunc 不截断输出文件
  noerror 读取数据发生错误后仍然继续
  fdatasync 结束前将输出文件数据写入磁盘
  fsync 类似上面,但是元数据也一同写入

FLAG 符号可以是:

append 追加模式(仅对输出有意义;隐含了conv=notrunc)
  direct 使用直接I/O 存取模式
  directory 除非是目录,否则 directory 失败
  dsync  使用同步I/O 存取模式
  sync  与上者类似,但同时也对元数据生效
  fullblock 为输入积累完整块(仅iflag)
  nonblock 使用无阻塞I/O 存取模式
  noatime 不更新存取时间
  nocache 丢弃缓存数据
  noctty 不根据文件指派控制终端
  nofollow 不跟随链接文件
  count_bytes  treat 'count=N' as a byte count (iflag only)
  skip_bytes  treat 'skip=N' as a byte count (iflag only)
  seek_bytes  treat 'seek=N' as a byte count (oflag only)

Sending a USR1 signal to a running 'dd' process makes it
print I/O statistics to standard error and then resume copying.

$ dd if=/dev/zero of=/dev/null& pid=$!
  $ kill -USR1 $pid; sleep 1; kill $pid
  18335302+0 records in
  18335302+0 records out
  9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

Options are:

--help  显示此帮助信息并退出
      --version  显示版本信息并退出

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告dd 的翻译错误
要获取完整文档,请运行:info coreutils 'dd invocation'

												

交换分区 在dd命令执行期间 top 其消耗系统约14%的cpu,而mem占比约为0的更多相关文章

  1. 磁盘,fdisk分区,MBR,dd命令

    光盘和磁盘.u盘.软盘.硬盘有什么区别 ①光盘: cdrom/dvdrom:光驱(光盘驱动器)    rom:只读    ram:可以擦写    cd:700M    dvd:4G ②软盘:flopp ...

  2. 【Linux命令】磁盘分区,格式化,挂载命令,创建交换分区(fdisk,mkfs,mount,umount)

    友情链接 磁盘分区,格式化,挂载,创建交换分区:https://www.cnblogs.com/HeiDi-BoKe/p/11936998.html RAID工作级别:https://www.cnbl ...

  3. linux内存不足,swap交换分区创建

    为什么需要swap 根 据Redhat公司的建议,Linux系统swap分区最适合的大小是物理内存的1-2倍.不过Linux上有些软件对swap分区得需求较大,例如要顺 利执行Oracle数据库软件, ...

  4. CentOS 挂载(U盘NTFS格式,新硬盘,增加交换分区,扩展根分区等)

    1.挂载fat或者fat32分区的U盘 如果是用VM安装的linux,在vm里挂载U盘有两个前提: 第一,主机里的service要启动: 第二,U盘是连接到虚拟机,而不是主机,需要确认这点: 2.使用 ...

  5. 6个关于dd命令备份Linux系统的例子

    数据丢失带来的损失是相当昂贵的.关键数据的丢失会对各种规模的企业带来影响.有几种方法来备份Linux系统,包括rsync的和rsnapshot等.本文提供有关使用dd命令备份Linux系统的6个实例. ...

  6. centos 交换分区

    内容来自:http://www.huzs.net/?p=1683 一般在桌面型的用不到,因为现在内存都比较大,服务器就不一样了,但是建议无论是在桌面还是服务器上,都设置 swap 以下操作都是在 ro ...

  7. (转)Linux下增加交换分区的大小

    场景:最近在Linux环境安装ELK相关软件时候发现机器特别的卡,所以就查看了Linux机器的内存使用情况,发现是内存和交换分区空间太小了. 对于虚拟机中的内存问题,可以直接通过更改虚拟机的硬件进行解 ...

  8. linux 添加交换分区

    [操作简介] 增加swap分区方法: 1.新建磁盘分区作为swap分区 2.用文件作为swap分区 (操作更简单,我更常用) 下面介绍这两种方法:(都必须用root权限,操作过程应该小心谨慎.)   ...

  9. Linux - 创建交换分区 swap

    购买的 1GB 内存的 Linux 小机器,在编译安装 PHP 的时候内存捉急,只好开启 swap 交换分区来增大内存. [root@VM_139_38_centos php-7.2.12]# cat ...

随机推荐

  1. Python_编程题集_002_菱形

    2.编写程序实现: n=5,输出: * *** ***** *** * n=6,输出: * *** ***** ***** *** * n为任意大于1的正整数. 解: #思路: # 第一步:判断行数, ...

  2. Sublime Text3 解决中文乱码 & 可用注册码 & 设置默认打开方式

    Sublime Text3注册码 Sublime Text Build 3065 License key 复制如下三个任意一个正版注册码即可 -– BEGIN LICENSE -– Andrew We ...

  3. 一个python爬虫协程的写法(gevent模块)

    from bs4 import BeautifulSoup import requests import gevent from gevent import monkey, pool monkey.p ...

  4. Asp.Net Thread is being Aborted

    Asp.Net做的一个程序,通过JQuery的Ajax调用,程序执行的数据时间比较长,程序部署到服务器后执行一段时间后就弹出执行失败的对话框,日志记录的错误信息是“正在中止线程”. 查错过程: 1.根 ...

  5. CSS介绍&选择器&选择器优先级

    CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTML元素. 当浏览器读到一个样式表,它就会按照这个样式表来对文档进行格式化(渲染). CSS语法 '''se ...

  6. canvas跟随页面滑动后准确定位到真实坐标

    先来了解一个属性: getBoundingClientRect() 这个方法返回一个矩形对象,包含四个属性:left.top.right和bottom.分别表示元素各边与页面上边和左边的距离. var ...

  7. kvm虚拟化学习笔记(二)之linux kvm虚拟机安装

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

  8. 对dispatch_async到主线程的逻辑封装成C/C++接口类型

    背景:代码里面有时候会把将要运行的内容放到主线程里面运行,但假设已经是主线程里面的代码调用dispatch_async的时候偶尔会出现crash,所以就须要推断是否已经在主线程里面了. 通常的做法类似 ...

  9. HTML的DIV如何实现垂直居中

    外部的DIV必须有如下代码 display:table-cell; vertical-align:middle;   这样可以保证里面的东西,无论是DIV还是文本都可以垂直居中

  10. Android消息机制1-Handler(Java层)(转)

    转自:http://gityuan.com/2015/12/26/handler-message-framework/ 相关源码 framework/base/core/java/andorid/os ...