线上日志收集是很正常的业务,一般由运营来处理,现在给一段代码来实现日志的收集,打包以及上传到s3备份存储,请看代码:
基本上已经够用了,需要定义自己的变量就好!
Focus on php and open source.
线上日志收集是很正常的业务,一般由运营来处理,现在给一段代码来实现日志的收集,打包以及上传到s3备份存储,请看代码:
基本上已经够用了,需要定义自己的变量就好!
Merry Christmas!送给我,也送给我未过门的妻子,今天也是我的生日,祝我生日快乐!!
今天和兰兰,在小区门口的香辣居吃了一条烤鱼,味道不错,只是价格稍微贵了点,然后我们去了附近的沃尔玛,虽然兰兰忘记了我的生日,但是我没有怪罪她,只要她在我身边,陪着我,我已经足够了,可是她还是很想给我买一个蛋糕,说毕竟是生日,没有蛋糕咋行,我说我不喜欢吃蛋糕,想作罢,但是她还是很认真的一定要给我买一个,我说那就买一个mini的就好,然后我们去了沃尔玛,选了一个10块钱的蛋糕,4英寸,很实惠,兰兰问我晚上吃面好好,我就知道她是想我健康,长寿,因为她希望我活的比她长,她害怕失去我,一个人很孤独,我还是应了她,我说好啊,然后我们来了虾仁,面条,还有西红柿,鸡蛋家里有,也就没买了,我们回到家,她有点累,然后回家休息!我们一起开始吃蛋糕,然后兰兰说,许个愿吧,我说许愿做什么,最后我还是许个愿,因为这个愿望我想不仅仅属于我,也属于她,希望我的2017会有一个不一样的自己,生活!
我们在一起争吵了许多次,磨合了许多次,也伤感了许多次,但是这些都没能让我们真正的放弃彼此,而是更让我们珍惜彼此!爱,如此的奇妙,因为爱,才有那份征服自己和生活的勇气,因为爱,才不让自己变得没有任何责任心,因为爱,北京的雾霾也不会阻止我们相见!好久没有抒情了,还记得在学校文学社写抒情诗的自己,那么的沉迷,以至于不能自我!可惜,没能长久的保持那份坚持,现在看技术方面的书籍比较多点,都忘了如何去表达!
希望自己的2017,有勇气,有智慧,变得更聪明,更好驾驭自己,走向生活,为爱而生,也为我那可爱的,嫌弃我,陪伴我的人儿,追寻更多的幸福!hello world!hello,2017!
关于线上问题,是真正能够让我们成长的最好的方式,所以需要不断的积累,特别是大数据量时引起的一系列问题,包括人为的和线上的:
1.个人行为造成的问题,某同学想修改下数据表字段的类型,修改了一个几百万数据量的表,修改过程中会导致SQL阻塞,进一步导致请求阻塞,以至于整个系统请求平均延迟上升,产生了蝴蝶效应。如果量级更大的话,影响时间会更长,以至于整个系统不可用
总结:
线上的大表,因为都是基于innodb存储引起,修改引起的代价是比较大的,可能会锁表,索引尽可能的少执行这种操作,需要做好测试评估好执行影响时间
2.应用场景引发的问题,对于直播产品,视频直播结束,会向观众发送直播已经结束的消息,而这种消息是同时发送的,这样就会引起大量的数据产生和消费,造成的影响是,服务器消息堆积,客户端不知道直播是否结束,客户端仍然还在聊天室
总结:
在一定的时间内,比如1min, 离散的发送消息,让客户端能够在有限的时间内退出聊天室,不至于影响产品的用户体验
3.redis错误,read error on connection
这个错误是偶尔遇到,有同学通过修改php soctet超时时间来修复该问题
或者在脚本中添加
来解决该问题,但是这种解决方式并不是最好,而且这种方式需要重启php-fpm进程才可以生效
4.服务配置引起的问题,新开一个elb,支持cloudfront CDN支持,针对某个地区,将xxx.xxx.net这个域名,解析到cloudfront地址上,经由cloudfront再到后端elb进行访问,出现服务访问不了的情况,经运维协查,是cloude front服务配置问题导致
总结:
线上配置,需要谨慎修改,支持各种环境(线上,开发,测试,联调)发布部署配置文件的管理
5.设计问题,redis大key如何解,有时候对于好友关系等出现长尾数据的时候,存和读都会遇到问题,一般对大key的读,使用分页读,如果存储的数据量过大,1000w,那么做数据迁移还是数据恢复就会有问题,所以,单key的数据量的存储,不应过大
总结:
大key,可以使用应用层对id进行hash,生成统一前缀的key,自动实现key的查找
6.高并发,大数据引起最初设计的变化的问题,随着用户量的增加,uv上升,导致之前的设计请求量增加,系统压力增大,这样需要在原先的设计上,增加一些策略,当然,这种策略的增加需要产品的支持,比如消息发送,对任何用户等级之间的用户发送私信,当大网红直播时,这样导致消息量剧增,如果同时直播数比较多,产生的消息量会非常大,这样,可以增加一些策略来减少这种压力,比如只有达到某个等级的用户,在直播的时候,才对其粉丝发送私信,这样就大大的减少了消息量的产生,当然也可以在技术上支持
7.减少存储系统的压力,对于给予协助处理服务程序的数据,比如算法,这种服务的特性是非实时的,或者接近实时,对于这种数据的存储,不需要放到内存中存储,可以使用kafka来存储,将算法服务接入该系统,获取数据,并将数据的结果写入前端服务器或者内存中,供前端服务使用
8.线上日志,一种为数据日志,提供分析平台使用,而另外一种属于业务日志,供问题定位,对于业务日志,需要做到能准确定位所发生的问题,用户线上问题排查
9.无状态设计和有状态设计,无状态设计,比如静态文件,或者使用已有的信息,能拿到所需要的静态资源数据信息,怎样区权衡是使用有状态设计,还是使用无状态设计,还是有无状态设计相结合,需要考虑到对系统性能的影响,有多大的影响,增加有状态设计会产生什么多大的存储资源的损耗?是否是热点数据,是否需要将数据分多次多状态存储和维护?如果数据量不大,而且是基于热点,那么最好还是使用有状态设计,不会产生太多的资源损耗问题,性能还是实现的逻辑也是可以控制的
10.系统架构设计,使用ha来实现各节点之间活跃监控,增强系统的容错处理和可靠性
11.redis并发症控制,可以使用setnx来替换set
初涉这门语言,该语言以其高性能并发编程而被程序员们所喜欢,虽然鄙人还没涉足如何很好的去运用这门语言来支持现有的产品性能提升,只是抱着学习的态度,了解一门新的语言有哪些特性,可以为我所用,仅此,写下此篇,来记录自己学习历程!
|
|
少即是多,你理解得越好,你将变得越简洁!这里的少和多主要是针对GO和C、C++之间的比较,下面看看Go做了些什么:
Doug Mcilroy,Unix管道的最终发明人,在1964年(!)写道:
如果C++和Java注重类型继承和类型系统的分类学,那么Go就注重组合,是一门关于(功能上的)组合和(调用上的)耦合的语言。写这些,只是为了便于理解go语言是什么,便于更快的理解go语言
|
|
1.自动垃圾回收
2.更丰富的内置类型
3.函数多返回值
4.错误处理
5.匿名函数和闭包
6.类型和接口
7.并发编程
8.反射
9.语言交互性
….以后补充….
|
|
…..以后补充…..
|
|
1.cache2go
https://github.com/muesli/cache2go
比较简单的一个缓存库,代码量很少,适合新手学习,可以学习到锁、goroutines等
2.groupcache
https://github.com/golang/groupcache
与memcached同一作者,相当于是memcached的go语言实现
3.nsq
https://github.com/bitly/nsq
消息分发平台,阅读代码可以了解到很多分布式、负载均衡等方面的编程
4.docker
https://github.com/docker/docker
成为了高手后可以研究下其实现
5.go语言开发工具集
https://github.com/golang/go/wiki/Projects
先看下这个10个命令:
uptime
dmesg | tail
vmstat 1
mpstat -P ALL 1
pidstat 1
iostat -xz 1
free -m
sar -n DEV 1
sar -n TCP,ETCP 1
top
下面讲解下这个10个命令都是用来做什么的,怎么用
uptime
|
|
uptime – show how long system has been running
DESCRIPTION
The uptime utility displays the current time, the length of time the system has been up, the number of users, and the load average of the system over the
last 1, 5, and 15 minutes.
该命令用来查看系统的运行时间和负载情况,分别对应以下列
当前时间 启动运行时间 系统启动时间 当前系统用户数 系统最近1分钟、5分钟、15分钟系统的负载情况
dmesg | tail
dmesg – display the system message buffer
DESCRIPTION
Dmesg displays the contents of the system message buffer. This command needs to be run as root.
该命令用来显示linux内核的环形缓冲区(kernel ring buffer)信息,从中获得诸如系统架构、cpu、挂载的硬件,RAM等多个运行级别的大量的系统信息,当计算机启动时,系统内核(操作系统的核心部分)将会被加载到内存中,在加载的过程中会显示很多的信息,在这些信息中我们可以看到内核检测硬件设备,主要是硬件检测,包括磁盘sda,hda,usb等
vmstat 2 1
每两秒采集一次服务器的状态 2 时间间隔 1 次数
NAME
vmstat - Report virtual memory statistics
SYNOPSIS
vmstat [-a] [-n] [-t] [-S unit] [delay [ count ]]
vmstat [-s] [-n] [-S unit]
vmstat [-m] [-n] [delay [ count ]]
vmstat [-d] [-n] [delay [ count ]]
vmstat [-p disk partition] [-n] [delay [ count ]]
vmstat [-f]
vmstat [-V]
DESCRIPTION
vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory
reports are instantaneous in either case.
DESCRIPTION FOR VM MODE
Procs
r: The number of processes waiting for run time.(在运行队列中等待cpu进程数)
b: The number of processes in uninterruptible sleep.(等待I/O的进程数)
Memory
swpd: the amount of virtual memory used.(切换到内存交换区的内存数量,如果swpd比较大,但是si,so一直为0,系统性能也是正常的)
free: the amount of idle memory.
buff: the amount of memory used as buffers.(一般对块设备的读写进行缓存)
cache: the amount of memory used as cache.(page cache数量,一般作为文件系统的缓存,如果cache比较大,说明用到cache的文件比较多,如果I/O的bi比较小,说明文件系统效率比较好)
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
Swap
si: Amount of memory swapped in from disk (/s).(从磁盘交换进内存的页数量)
so: Amount of memory swapped to disk (/s).(从内存交换到磁盘的页数量)
IO
bi: Blocks received from a block device (blocks/s).(从磁盘读到内存的块数)
bo: Blocks sent to a block device (blocks/s).(从内存写入磁盘的块数)
System
in: The number of interrupts per second, including the clock.(每秒设备中断数)
cs: The number of context switches per second.(每秒产生的上下文切换次数,cs正常情况下,应小于I/O的包传输速率)
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time) (用户进程占用cpu的时间比)
sy: Time spent running kernel code. (system time) (系统进程占用cpu的时间比)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.(中央处理器空闲时间占用比)
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
FIELD DESCRIPTION FOR DISK MODE
Reads
total: Total reads completed successfully
merged: grouped reads (resulting in one I/O)
sectors: Sectors read successfully
ms: milliseconds spent reading
Writes
total: Total writes completed successfully
merged: grouped writes (resulting in one I/O)
sectors: Sectors written successfully
ms: milliseconds spent writing
IO
cur: I/O in progress
s: seconds spent for I/O
ms: milliseconds spent writing
IO
cur: I/O in progress
s: seconds spent for I/O
FIELD DESCRIPTION FOR DISK PARTITION MODE
reads: Total number of reads issued to this partition read sectors: Total read sectors for partition
writes : Total number of writes issued to this partition
requested writes: Total number of write requests made for partition
FIELD DESCRIPTION FOR SLAB MODE
cache: Cache name
num: Number of currently active objects
total: Total number of available objects
size: Size of each object
pages: Number of pages with at least one active object
totpages: Total number of allocated pages
pslab: Number of pages per slab
如果r经常大于4 ,且id经常小于40,表示中央处理器的负荷很重。 如果bi,bo 长期不等于0,表示物理内存容量太小
mpstat -P ALL 1
NAME
mpstat - Report processors related statistics.
DESCRIPTION
The mpstat command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed. If no activity has been selected, then the default report is the CPU utilization report.
The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that processors statistics are to be reported for the time since system startup (boot). The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count determines the number of reports generated at interval seconds apart. If the interval parameter is speci-fied without the count parameter, the mpstat command generates reports continuously.
OPTIONS
-A This option is equivalent to specifying -I ALL -u -P ALL
-P { cpu [,…] | ON | ALL }
Indicate the processor number for which statistics are to be reported. cpu is the processor number. Note that processor 0 is the first processor.The ON keyword indicates that statistics are to be reported for every online processor, whereas the ALL keyword indicates that statistics are to be reported for all processors.
-u Report CPU utilization. The following values are displayed:
CPU Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
%usr Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%sys Show the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include time spent servicing hardware and software interrupts.
%iowait Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%irq Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.
%soft Show the percentage of time spent by the CPU or CPUs to service software interrupts.
%steal Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual proces-sor.
%guest Show the percentage of time spent by the CPU or CPUs to run a virtual processor.
%idle Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
ipdstat 1
NAME
pidstat - Report statistics for Linux tasks.
DESCRIPTION
The pidstat command is used for monitoring individual tasks currently being managed by the Linux kernel. It writes to standard output activities for every task selected with option -p or for every task managed by the Linux kernel if option -p ALL has been used. Not selecting any tasks is equivalent to speci-fying -p ALL but only active tasks (tasks with non-zero statistics values) will appear in the report.
The pidstat command can also be used for monitoring the child processes of selected tasks. Read about option -T below.
The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that tasks statistics are to be reported for the time since system startup (boot). The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the pidstat command generates reports continuously.
You can select information about specific task activities using flags. Not specifying any flags selects only CPU activity.
EXAMPLES
pidstat 2 5
Display five reports of CPU statistics for every active task in the system at two second intervals.
pidstat -r -p 1643 2 5
Display five reports of page faults and memory statistics for PID 1643 at two second intervals.
pidstat -T CHILD -r 2 5
Display five reports of page faults statistics at two second intervals for the child processes of all tasks in the system. Only child processes with non-zero statistics values are displayed.
iostat -xz 1
iostat主要用于监控系统设备的IO负载情况
NAME
iostat - Report Central Processing Unit (CPU) statistics and input/output statistics for devices, partitions and network filesystems (NFS).
DESCRIPTION
The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.
The first report generated by the iostat command provides statistics concerning the time since the system was booted. Each subsequent report covers the time since the previous report. All statistics are reported each time the iostat command is run. The report consists of a CPU header row followed by a row of CPU statistics. On multiprocessor systems, CPU statistics are calculated system-wide as averages among all processors. A device header row is displayed followed by a line of statistics for each device that is configured. When option -n is used, an NFS header row is displayed followed by a line of statistics for each network filesystem that is mounted.
The interval parameter specifies the amount of time in seconds between each report. The first report contains statistics for the time since system startup (boot). Each subsequent report contains statistics collected during the interval since the previous report. The count parameter can be specified in conjunction with the interval parameter. If the count parameter is specified, the value of count determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the iostat command generates reports continuously.
REPORTS
The iostat command generates three types of reports, the CPU Utilization report, the Device Utilization report and the Network Filesystem report.
CPU Utilization Report
The first report generated by the iostat command is the CPU Utilization Report. For multiprocessor systems, the CPU values are global averages among all processors. The report has the following format:
%user
Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice
Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%system
Show the percentage of CPU utilization that occurred while executing at the system level (kernel).
%iowait
Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%steal
Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
%idle
Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
Device Utilization Report
The second report generated by the iostat command is the Device Utilization Report. The device report provides statistics on a per physical device or par-tition basis. Block devices for which statistics are to be displayed may be entered on the command line. Partitions may also be entered on the command line providing that option -x is not used. If no device nor partition is entered, then statistics are displayed for every device used by the system, and providing that the kernel maintains statistics for it. If the ALL keyword is given on the command line, then statistics are displayed for every device defined by the system, including those that have never been used. The report may show the following fields, depending on the flags used.
|
|
Network Filesystem report
The Network Filesystem (NFS) report provides statistics for each mounted network filesystem. The report shows the following fields
OPTIONS
-c Display the CPU utilization report.
-d Display the device utilization report.(显示磁盘的使用状态)
-K 对块设备,强制使用Kilobytes为单位
-x Display extended statistics. This option works with post 2.5 kernels since it needs /proc/diskstats file or a mounted sysfs to get the statistics. This option may also work with older kernels (e.g. 2.4) only if extended statistics are available in /proc/partitions (the kernel needs to be patched for that).(显示I/O相关的扩展数据)
-n Display the network filesystem (NFS) report. This option works only with kernel 2.6.17 and later.
-p [ { device [,…] | ALL } ]
The -p option displays statistics for block devices and all their partitions that are used by the system. If a device name is entered on the command line, then statistics for it and all its partitions are displayed. Last, the ALL keyword indicates that statistics have to be displayed for all the block devices and partitions defined by the system, including those that have never been used. Note that this option works only with post 2.5 kernels.
EXAMPLES
iostat
Display a single history since boot report for all CPU and Devices.
iostat -d 2
Display a continuous device report at two second intervals.
iostat -d 2 6
Display six reports at two second intervals for all devices.
iostat -x hda hdb 2 6
Display six reports of extended statistics at two second intervals for devices hda and hdb.
iostat -p sda 2 6
Display six reports at two second intervals for device sda and all its partitions (sda1, etc.)
主要看await和%util的值,await是否大于5ms,%util是否大于80%
free -m
NAME
free - Display amount of free and used memory in the system
DESCRIPTION
free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The shared memory column should be ignored; it is obsolete.
sar -n DEV 1
NAME
sar - Collect, report, or save system activity information.
DESCRIPTION
The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters, writes information the specified number of times spaced at the specified intervals in seconds. If the interval parameter is set to zero, the sar command displays the average statistics for the time since the system was started. If the interval parameter is specified without the count parameter, then reports are generated continuously. The collected data can also be saved in the file specified by the -o file-name flag, in addition to being displayed onto the screen. If filename is omitted, sar uses the standard system activity daily data file, the /var/log/sa/sadd file, where the dd parameter indicates the current day. By default all the data available from the kernel are saved in the data file.
The sar command extracts and writes to standard output records previously saved in a file. This file can be either the one specified by the -f flag or, by default, the standard system activity daily data file.
Without the -P flag, the sar command reports system-wide (global among all processors) statistics, which are calculated as averages for values expressed as percentages, and as sums otherwise. If the -P flag is given, the sar command reports activity which relates to the specified processor or processors. If -P ALL is given, the sar command reports statistics for each individual processor and global statistics among all processors.
You can select information about specific system activities using flags. Not specifying any flags selects only CPU activity. Specifying the -A flag is equivalent to specifying -bBdqrRSvwWy -I SUM -I XALL -n ALL -u ALL -P ALL.
The default version of the sar command (CPU utilization report) might be one of the first facilities the user runs to begin system activity investigation,because it monitors major system resources. If CPU utilization is near 100 percent (user + nice + system), the workload sampled is CPU-bound.If multiple samples and multiple reports are desired, it is convenient to specify an output file for the sar command. Run the sar command as a background process. The syntax for this is:
sar -o datafile interval count >/dev/null 2>&1 &
All data is captured in binary form and saved to a file (datafile). The data can then be selectively displayed with the sar command using the -f option.Set the interval and count parameters to select count records at interval second intervals. If the count parameter is not set, all the records saved in the file will be selected. Collection of data in this manner is useful to characterize system usage over a period of time and determine peak usage hours.
Indicate the number of transfers per second that were issued to the device. Multiple logical requests can be combined into a single I/O
request to the device. A transfer is of indeterminate size.
rd_sec/s
Number of sectors read from the device. The size of a sector is 512 bytes.
wr_sec/s
Number of sectors written to the device. The size of a sector is 512 bytes.
avgrq-sz
The average size (in sectors) of the requests that were issued to the device.
avgqu-sz
The average queue length of the requests that were issued to the device.
await
The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue
and the time spent servicing them.
svctm
The average service time (in milliseconds) for I/O requests that were issued to the device.
%util
Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs
when this value is close to 100%.
sar -n TCP,ETCP 1
top
NAME
top - display Linux tasks
a: PID – Process Id
The task’s unique process ID, which periodically wraps, though never restarting at zero.
b: PPID – Parent Process Pid
The process ID of a task’s parent.
c: RUSER – Real User Name
The real user name of the task’s owner.
d: UID – User Id
The effective user ID of the task’s owner.
e: USER – User Name
The effective user name of the task’s owner.
f: GROUP – Group Name
The effective group name of the task’s owner.
g: TTY – Controlling Tty
The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case you’ll see ’?’ displayed.
h: PR – Priority
The priority of the task.
i: NI – Nice value
The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task’s dispatchability.
j: P – Last used CPU (SMP)
A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).
k: %CPU – CPU usage
The task’s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if ’Irixmode’ is Off, top will operate in ’Solaris mode’ where a task’s cpu usage will be divided by the total number of CPUs. You toggle ’Irix/Solaris’ modes with the ’I’ interactive command.
l: TIME – CPU Time 进程使用cpu时间总计,单位秒
Total CPU time the task has used since it started. When ’Cumulative mode’ is On, each process is listed with the cpu time that it and its dead children has used. You toggle ’Cumulative mode’ with ’S’, which is a command-line option and an interactive command. See the ’S’ interactive command for addi-tional information regarding this mode.
m: TIME+ – CPU Time, hundredths 进程使用cpu时间总计, 单位1/100秒
The same as ’TIME’, but reflecting more granularity through hundredths of a second.
n: %MEM – Memory usage (RES) 使用物理内存占用比
A task’s currently used share of available physical memory.
o: VIRT – Virtual Image (kb)虚拟内存使用量
The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. (Note: you can define the STATSIZE=1 environment variable and the VIRT will be calculated from the /proc/#/state VmSize field.)
p: SWAP – Swapped size (kb) 使用虚拟内存,被换出的大小
Per-process swap values are now taken from /proc/#/status VmSwap field.
q: RES – Resident size (kb) 进程使用的,未被还出的物理内存大小
The non-swapped physical memory a task has used.
RES = CODE + DATA.
r: CODE – Code size (kb) 可执行的代码占用物理内存的大小
The amount of physical memory devoted to executable code, also known as the ’text resident set’ size or TRS.
s: DATA – Data+Stack size (kb) 可执行代码以外的部分(数据段+棧)占用物理内存的大小
The amount of physical memory devoted to other than executable code, also known as the ’data resident set’ size or DRS.
t: SHR – Shared Mem size (kb) 共享内存大小
The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes.
u: nFLT – Page Fault count 页面错误次数
The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that
v: nDRT – Dirty Pages count 最后一次写入,未被修改的的页面数
The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page.
w: S – Process Status 进程状态
The status of the task which can be one of:
’D’ = uninterruptible sleep()
’R’ = running
’S’ = sleeping
’T’ = traced or stopped
’Z’ = zombie(僵尸进程数)
Tasks shown as running should be more properly thought of as ’ready to run’ – their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top’s delay interval and nice value.
x: Command – Command line or Program name 命令名
Display the command line used to start a task or the name of the associated program. You toggle between command line and name with ’c’, which is both a command-line option and an interactive command.When you’ve chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in paren-theses, as in this example:
( mdrecoveryd )
Either form of display is subject to potential truncation if it’s too long to fit in this field’s current width. That width depends upon other fields selected, their order and the current screen width.
Note: The ’Command’ field/column is unique, in that it is not fixed-width. When displayed, this column will be allocated all remaining screen width (up to the maximum 512 characters) to provide for the potential growth of program names into command lines.
y: WCHAN – Sleeping in Function 睡眠状态的进程系统函数名
Depending on the availability of the kernel link map (’System.map’), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash (’-’) in this column.
Note: By displaying this field, top’s own working set will be increased by over 700Kb. Your only means of reducing that overhead will be to stop and restart top.
z: Flags – Task Flags 任务标志
This column represents the task’s current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are offi-cially documented in
以上均摘录自手册,供大家参考,使用!
对最近的工作做一个总结和反思,最近在处理消息分片的工作,先介绍下应用的场景:
我们在做一个直播的产品,直播中会存在很多消息,这样就需要对消息进行处理,然后回放的时候,会用到这些存储的文件,我们目前使用的第三方的聊天室系统,需要对第三方的消息同步到我们的系统存储起来,一方面便于查询问题,因为消息内容中除了第三方的自定义的协议之外,也会涉及到我们业务数据的上报;另外一方面,不需要依赖第三方服务,对自己的数据管控。在改版之前,第三方会在直播结束,会回调我们的接口,进行消息的同步,写入异步队列,实现串行处理,之前每个直播消息,会生成独立的一个文件,放到云存储s3,由于消息文件过大,导致有些回播在下载消息文件的过程中,加载时间太慢,甚至导致客户端app直接崩溃,为此,之前有人改过一版,只是对于消息过于大的文件,进行了不处理,也就是完全的抛弃掉,回播不会存在聊天消息,这种处理太过于武断,没有从根本上解决问题
在处理这个问题的过程中,遇到了一些问题
之前的处理方式:
将消息文件从redis落地,将消息文件存放于磁盘,然后用shell脚本实现同步到s3
方案一
我没有修改既有的这种方式,甚至没有对这种方式产生任何的质疑, 于是做了如下的设计
1.新增接口,提供消息分片的文件列表,需要服务端存储某个视频的消息分片的文件的列表
2.仍然使用既有使用shell脚本同步消息文件的方案
这样的设计有什么问题呢?
1.浪费了存储空间,这些消息文件是静态的文件,生成之后就不会变,所以并不需要把消息分片文件列表存放于redis中
2.消息文件的同步,将消息文件存放于本地磁盘,然后使用shell脚本同步,而且同步进程使用的单进程,实践证明,这种方式并不是最好的,由于产生的文件的数量比较多,导致消费脚本处理不过来,产生消息文件的积压
方案二
1.做好对旧版本的兼容,对接口进行修改,提供消息文件的索引文件,索引文件是消息分片文件上传到s3之后的文件列表
2.不基于shell脚本处理,基于s3提供的sdk,完全使用同步的方式进行处理,即不将redis中的消息内容落地处理,不生成消息文件
3.动态生成消息分片文件的时候,同时生成消息索引文件,并同步到s3
索引文件:
这样,既解决了服务端的存储问题,不用再存储消息分片文件了,直接客户端通过接口请求,拿到消息索引文件,通过解析消息索引文件,得到所需要的消息索引文件列表,同时解决了消息文件存放于存盘,产生的消费能力跟不上导致的文件积压的问题,如果文件比较多,还可以对回调任务处理脚本使用多进程的方式,不用考虑到是否会产生多个进程同时消费一个消息文件的问题,完美支持多进程,这样设计似乎完美了吧?
真的完美么?
方案三
在方案二的基础上做了以下的修改
方案二会产生什么问题呢?
1.客户端要下载消息文件,需要先请求索引文件接口,下载并解析索引文件,获取消息分片文件列表,客户端同学会说,你的接口太难用了得改啊
2.流量问题,移动端应用,最需要考虑的问题之一,就是能省流量
如何更友好的处理这些问题呢?
1.简化接口,还是使用索引列表的方式返回,但是处理方式跟方案一不同的地方是,服务端请求索引文件,解析并通过接口返回
2.生成的消息文件使用gz压缩,当然这个压缩需要s3支持,开启s3的gz压缩模式,减少消息的传输
到此,也算是比较完美的了,不知道还没有比较好的方案来处理这个问题?希望能得到大家的交流!
总结:
1.在接口升级的过程中需要考虑到客户端新老版本的兼容性
2.对于同步处理还是异步处理的选择,根据特定的业务场景进行选择,考虑有没有必要使用异步处理,不是所有场景都适合使用异步处理的方式
3.文件存储,考虑磁盘的使用文件,目录划分
4.消费模型,必须需要考虑生产者和消息者之间能力匹配问题,不然会产生积压
5.对于数据的处理方式和存储方式,不是所有的数据都需要使用内存或者数据库存储,可以使用云存储,结合cdn技术,更好的管理静态文件
6.对于考虑一个方案的时候,需要做更多的可能性测试,通过测试来选取最佳方案
7.在思考方案的时候,需要从头到尾的考虑整个的数据的处理过程,可能是一个回路,只是变更一种数据获取方式,所以考虑的时候,尽可能的考虑每一个数据上处理的环节
人因为梦想而伟大,产品因为一个更好的技术方案而解放我们,多思考细节的东西,才能挖掘别人看不到的东西,一切变化,都因为在变!!
工作中有时候需要使用shell来做一些文件处理,但是在使用shell脚本之前,先确定是否使用该方案来处理,以下是我一个位上线的脚本
只是方案进行了修改,不使用这种方式来处理,由于需要清理分支,所以记录下来!
|
|
该方法使用0和1,通过构建数组的方式,使用动态内存分配的方式,来求素数
问题:一个有序序列,如何找到绝对值最小的元素
|
|
输出:
输出了所有的绝对值等于1的元素,但是这个问题有哪些需要注意的呢?
宏是关键字define定义,一种简单的字符串替换方式,可以分为带参数和不带参数两种。
1.#和##在宏中的使用
对参数x使用#引用,实现对参数器字符数组化预处理,如果调用ERROR_LOG(“error log”),则输出Error:“error log“
使用##,预处理器实现字符串之间分隔连接方式,如果调用TYPE(int,”user”), 则预处理之后int name_int_type,这样实现了变量的类型定义
可以使用这种方式来实现创建一个数组
2.do…while
使用do…while…来包裹,实现语言结构的独立
3.函数宏
调用lang_init(),实现c_init()函数的调用
4.宏参数
调用x = min(a, b);实际上是x = ((a) < (b) ? (a) : (b)); 执行
5.预定义宏
COUNTER,GFORTRAN,GNUC,GNUC_MINOR,GNUC_PATCHLEVEL,GNUG,STRICT_ANSI,VERSION,NO_INLINE,GNUC_GNU_INLINE,OPTIMIZE
等等
6.#ifdef …. #else …. #if … #endif
7.PHP中常见的宏
说起指针,不得不提下数组,因为两者在某些方面有相似之处,请看下面的代码:
数组在什么时候等同于指针呢?什么时候又不等同于指针呢?
1.数组和指针的访问方式
编译器编译的时候会生成一个符号表,这样a和p都在这个符号表里,每一个符号表,都有一个符号跟地址的对应关系,如下:
a–>9980
p–>4624
a–>9980–>+1–>+2–+3–>…->+i–>–>
编译器符号表地址9980
取i的值,将它与9980相加
取地址(9980+i)的内容
p–>4624–>5081–>data
编译器符号表地址 4624
取地址4624的内容,即5081
取地址5081的内容
也就是说,对于a而言,符号表的地址,即为数组a地址,然而对于p而言,符号表对应的地址,对应的是一个4字节的对象指针,而其内容存放的是一个地址,这个地址存储的数据即为指针所对应的数据。
2.使用指针来访问数组
p–>4624–>5081 —|(5081+i)| —5081–>+1–>+2–>+3–>…–>+i–>–>
编译器符号表的p地址4624,提取存储于此处的指针5801
取下标偏移量,将其与指针的值相加,产生一个地址
访问这个地址,取得子符
同样也能访问到数组的内容d,只是访问的方式略有不同,首先进行间接引用,然后按照下标偏移量直接访问。
3.指针所引用的数据,其地址可以是不连续的,而数组,其地址是连续的,指针使用malloc()和 free()来管理内存,且只有字符串才可以初始化指针,其它类型均不可以直接赋值,且初始化之后,是只读的,不可以修改其值 .
4.数组和指针,有且只有作为函数的参数的时候,才是等同的
这里数组既作为指针使用,也可以作为字符数组使用,只是因为printf是函数,参数中的数组和指针等同
又比如main函数
是等同的.
5.应用
a. 二维数组
等同,数组中单个元素的存储和引用实际上是以线性形式排列的内存重的,即以第一维作为组,第二位作为每个元素在组内的偏移量,这样线性排列.
b.函数指针
c.Iliffe向量,即将一个二维数组,创建一个一维数组,数组中的元素是指向其它东西的指针
my_array是一个二维数组,一个指向向量的指针数组