【资源不友好代码】

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数据可视化库-Matplotlib(一)

    今天我们来学习一下python的数据可视化库,Matplotlib,是一个Python的2D绘图库 通过这个库,开发者可以仅需要几行代码,便可以生成绘图,直方图,功率图,条形图,错误图,散点图等等 废 ...

  2. 自动化测试如何解析excel文件?

    前言 自动化测试中我们存放数据无非是使用文件或者数据库,那么文件可以是csv,xlsx,xml,甚至是txt文件,通常excel文件往往是我们的首选,无论是编写测试用例还是存放测试数据,excel都是 ...

  3. fstream,sstream的学习记录

    fstream: #include<iostream> #include<fstream> using namespace std; int main(){ ofstream ...

  4. Spring入门(1)——搭建简单的环境

    步骤: 1.下载spring框架开发包. 2.创建web项目并引入开发包. 3.创建java接口和相应的实现类. 4.编写spring的配置文件. 5.编写 测试类,并进行测试. 1.下载spring ...

  5. LeetCode07--整数反转

    ''' 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 ...

  6. 算法导论 第八章 线性时间排序(python)

    比较排序:各元素的次序依赖于它们之间的比较{插入排序O(n**2) 归并排序O(nlgn) 堆排序O(nlgn)快速排序O(n**2)平均O(nlgn)} 本章主要介绍几个线性时间排序:(运算排序非比 ...

  7. python接口自动化-token参数关联登录(登录拉勾网)

    前言 登录网站的时候,经常会遇到传token参数,token关联并不难,难的是找出服务器第一次返回token的值所在的位置,取出来后就可以动态关联了 登录拉勾网 1.先找到登录首页https://pa ...

  8. 大数据学习——hdfs客户端操作

    package cn.itcast.hdfs; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configur ...

  9. vs2010 相对路径

    相对路径是针对后缀为vcxproj文件而言的. 在VS的工程中常常要设置头文件的包含路径,当然你可以使用绝对路径,但是如果你这样设置了你只能在你自己的机器上运行该工程:如果其他人拷贝你的工程到其他机器 ...

  10. ***js常用方法汇总(源自实际中的项目)

    Q: 400-819-0717转8888,取后四位分机号 A: 方法一: alert("abcdefg".slice(-4));方法二:var str= "abcdefg ...