生命可以浪费在美好的事物之上 – I LIKE IT
你不要喊口号吧,口号是没有用的,如果你不调整自己的生活,不改变自己的理念,不珍惜你已有的自由,不为你安身的社会担负起当有的一份使命,那么你便闭嘴好了。
 RSS
Sponsored by
唯品会——一家专门做特卖的网站
唯品会——一家专门做特卖的网站
唯品会,一家专门做特卖的网站,每天 100 个品牌授权特卖、确保正品、确保特价、限量抢购。
Promoted by 唯品会

Xcode 编译调试 MySQL

By Chao Nie at 03 February 2015

1、从 MySQL 官方网站下载 MySQL 源码包

Alt text

2、生成 Xcode 工程文件,需要点时间

Alt text

3、工程文件生成好后在 Xcode 中打开该工程

Alt text

Alt text

4、刚打开工程的时候 Xcode 会索引整个工程,需要点时间

Alt text

5、Schema 切换到 install 开始编译安装,需要一点时间

Alt text

6、Xcode 编译安装完成后,可以在文件系统看到刚刚编译安装的 MySQL

Alt text

7、初始化 MySQL 系统库,安装过 MySQL 的同学都知道

Alt text

Alt text

8、Schema 切换到 mysqld 在 Xcode 中运行 MySQL 服务端,也可以运行其他的,如:mysqldump

Alt text

9、在 Terminal 里面可以看到运行好了的 MySQL 了,也可以登入尝试下,默认用户都是没有密码的

Alt text

10、编辑 mysqld 的 schema,调整运行参数方便针对性的调试特殊场景

Alt text

Alt text

MySQL  Xcode 
 

Puppet Error header too long

By Chao Nie at 12 January 2014

来自:http://thejmlcontinuum.blogspot.jp/2013/02/puppet-error-header-too-long.html

If you’re working with Puppet and you find that you get this error:

puppet cert --list
Error: header too long

Be mindful of your free space! I’ve now rolled out 20 servers or so in my puppet setup (soon to be duplicated to over 142 servers once I get these running right. All I’ll have to do is spin up a new server, give it an IP and hostname and tell it where the Puppet Master is and Puppet will handle the rest!), and I’ve found that I’m starting to easily fill up the drive with old reports. Especially when re-running puppet syncs more frequently than the normal 30 min run-interval. I started getting the above error with a lot of various puppet commands, the simplest one, just trying to list certs. Then I checked a “df -h”:

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              16G   15G     0 100% /

Oops! Using the following script I was able to clean up old reports easily. Set the “days” variable to as high as you want for your setup. I’m using Puppet Dashboard to pull in reports to a DB, so I don’t need to keep the yaml’s around too long.

#!/bin/sh
days="+1"       # more than a day old

for d in `find /var/lib/puppet/reports -mindepth 1 -maxdepth 1 -type d`
do
        find $d -type f -name \*.yaml -mtime $days |
        sort -r |
        tail -n +2 |
        xargs /bin/rm -f
done

In my case, since it tried to sync a new server ssl cert while the drive was full, the error came out to be due to not only the free space, but a corrupt cert. To find the offending cert and fix the issue, you’ll need to look through the /var/lib/puppet dir for the file. The host I was looking for is ‘betamem.example.com’ and I found it like this:

# cd /var/lib/puppet
# find ./|grep betamem
./ssl/ca/requests/betamem.example.com

I then removed the cert (held in /var/lib/puppet/ssl/certificate_requests/) from the agent on ‘betamem’ and told it to try again by cycling it’s puppet agent.

# rm -f /var/lib/puppet/ssl/certificate_requests/*
# /etc/init.d/puppet restart
Stopping puppet agent:                                     [  OK  ]
Starting puppet agent:                                     [  OK  ]

Tailing /var/log/messages on the master shows it’s got a new request, so let’s sign it:

# tail /var/log/messages -n1
puppet-master[22486]: betamem.example.com has a waiting certificate request
# puppet cert --sign betamem.example.com
Signed certificate request for betamem.example.com
Removing file Puppet::SSL::CertificateRequest at '/var/lib/puppet/ssl/ca/requests/betamem.example.com.pem'

Go back to the puppet agent and cycle it again, or just wait until the next run-interval and it should be back to normal!

Puppet 
 

来自http://z0mbix.github.io/blog/2012/03/01/use-nginx-and-passenger-to-power-your-puppet-master/

Where I work, we use Nginx wherever possible, so when it came to setting up a new Puppet Master I headed to the puppet docs only to find outdated docs on doing this. Most docs are centred around using Apache with Passenger. After much Googling, I found that not many people are doing this, or if they are, they haven’t documented it. This post documents the steps required to get this all running, and is based around doing so using RHEL or CentOS 5.x.

The version of Ruby that is included with Red Hat/CentOS 5.x is ancient, and should not be used. You should start with at least Ruby 1.8.7 (Plus Rubygems) or 1.9.2. See the Puppet Labs FAQ for details on the best version to use.I recommend you use the FrameOS repo that provides Ruby 1.8.7:

# rpm -Uvh http://rbel.frameos.org/rbel5

Install Ruby and Rubygems:

Now that’s out the way, let’s install puppet and puppet-server from yum.puppetlabs.com. You need to add the Puppet Labs yum repo which creates the file /etc/yum.repos.d/puppetlabs.repo file:

# rpm -ivh http://yum.puppetlabs.com/el/5/products/x86_64/puppetlabs-release-5-1.noarch.rpm

Now install Puppet:

# yum install -y puppet puppet-server

Install some dependency requirements to compile nginx:

# yum install -y gcc make pcre-devel zlib-devel openssl-devel pam-devel curl-devel rpm-build

You’ll probably want git at some stage too, so it’s easiest to add the EPEL repository and get it from there.

Install rake, rack and passenger ruby gems:

# gem install rake rack passenger --no-rdoc --no-ri

As nginx does not support dynamic module loading like Apache, and the official nginx RPMs provided by nginx.org are not compiled with Passenger suppport, we need to build nginx from source. I am not using the modrails.com yum repo to install the passenger enabled nginx as it relies on the default Ruby 1.8.5 and I don’t wish to use such an old version of Ruby. I’m also not using 1.9.2 as the Puppet Labs puppet packages are dependant on Ruby 1.8.x. If you wish to use Ruby 1.9.x, just install puppet as a gem (gem install puppet). This doesn’t setup the puppet user or install the RHEL/CentOS init script.

Download nginx latest stable source (Currently v1.0.12):

# wget http://nginx.org/download/nginx-1.0.12.tar.gz

Unpack it and move into the new directory:

# tar xvzf nginx-1.0.12.tar.gz
# cd nginx-1.0.12

Configure nginx, and add the passenger module:

# ./configure \
      --prefix=/opt/nginx \
      --conf-path=/etc/nginx/nginx.conf \
      --pid-path=/var/run/nginx.pid \
      --error-log-path=/var/log/nginx/error.log \
      --http-log-path=/var/log/nginx/access.log \
      --with-http_ssl_module \
      --with-http_gzip_static_module \
      --add-module=`passenger-config --root`/ext/nginx

This should end up with something similar to:

configuring additional modules
adding module in /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/nginx
checking for Math library ... found
 + ngx_http_passenger_module was configured
checking for PCRE library ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

It’s a good idea to build a RPM for nginx so you can quickly deploy it to other pupper servers. To do this I’m going to use Jordan Sissel’s superb fpm.

Let’s install the fpm rubygem:

# gem install fpm --no-rdoc --no-ri

Create a temporary location to create the RPM package:

# mkdir /tmp/installdir
# make
# make install DESTDIR=/tmp/installdir

Make some additional directories to add extra files to the RPM we are about to build:

# mkdir -p /tmp/installdir/etc/{sysconfig,rc.d/init.d,nginx/conf.d}

Next, you need an nginx init script. I created one based on the one from the nginx wiki and updated it with correct paths and removed the auto user creation stuff. I won’t paste the whole thing here, but you can download it (and all the other files) from my GitHub repo:

# curl -L https://raw.github.com/z0mbix/puppet-master-nginx-passenger/master/etc/rc.d/init.d/nginx -o /tmp/installdir/etc/rc.d/init.d/nginx

Make it executable:

# chmod 755 /tmp/installdir/etc/rc.d/init.d/nginx

Create the nginx sysconfig file /tmp/installdir/etc/sysconfig/nginx containing:

# Configuration file for the nginx service.
NGINX=/opt/nginx/sbin/nginx
CONFFILE=/etc/nginx/nginx.conf
LOCKFILE=/var/lock/subsys/nginx

Make it executable:

# chmod 755 /tmp/installdir/etc/sysconfig/nginx

Go home:

# cd ~

Create the RPM package:

# fpm -s dir \
  -t rpm \
  -n nginx-passenger \
  -v 1.0.12 \
  -C /tmp/installdir \
  -m "David Wooldridge <zombie@zombix.org>" \
  --url "http://nginx.org/" \
  --description "Nginx with the passenger module" \
  etc opt var

This should drop a nice new RPM in cwd called nginx-passenger-1.0.12-1.x86_64.rpm.

You can now install the RPM:

# rpm -ivh nginx-passenger-1.0.12-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:nginx-passenger        ########################################### [100%]

Create rack directory structure:

# mkdir -p /etc/puppet/rack/public

Copy rackup file to the correct place:

# cp /usr/share/puppet/ext/rack/files/config.ru /etc/puppet/rack/

Set the correct permissions, this is important:

# chown -R puppet:puppet /etc/puppet/rack/

Create the main nginx configuration file /etc/nginx/nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush      on;

    keepalive_timeout  65;

    # Passenger needed for puppet
    passenger_root  /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11;
    passenger_ruby  /usr/bin/ruby;
    passenger_max_pool_size 15;

    include /etc/nginx/conf.d/*.conf;
}

Make sure the passenger_root is set to whatever is returned by:

# passenger-config --root

The passenger configuration is taken from the Suggested Tweaks section of the Puppet Labs Apache/Passenger document found here and adapted for Nginx using the Passenger Nginx user guide found here. The defaults are all acceptable apart from passenger_max_pool_size which by default is only 6. This sets the maximum number of rack application instances that can be simultaneously active. I’m presuming you won’t be running your puppet master on less than 1GB of RAM, so setting this to 15. Adjust this to suit your hardware/RAM.

Also, if you have installed Ruby any where else, update passenger_ruby. Feel free to update worker_processes for your hardware.

Create the nginx puppet server config /etc/nginx/conf.d/puppet.conf:

server {
  listen                     8140 ssl;
  server_name                puppet puppet.example.com;

  passenger_enabled          on;
  passenger_set_cgi_param    HTTP_X_CLIENT_DN $ssl_client_s_dn; 
  passenger_set_cgi_param    HTTP_X_CLIENT_VERIFY $ssl_client_verify; 

  access_log                 /var/log/nginx/puppet_access.log;
  error_log                  /var/log/nginx/puppet_error.log;

  root                       /etc/puppet/rack/public;

  ssl_certificate            /etc/puppet/ssl/certs/puppet.example.com.pem;
  ssl_certificate_key        /etc/puppet/ssl/private_keys/puppet.example.com.pem;
  ssl_crl                    /etc/puppet/ssl/ca/ca_crl.pem;
  ssl_client_certificate     /etc/puppet/ssl/certs/ca.pem;
  ssl_ciphers                SSLv2:-LOW:-EXPORT:RC4+RSA;
  ssl_prefer_server_ciphers  on;
  ssl_verify_client          optional;
  ssl_verify_depth           1;
  ssl_session_cache          shared:SSL:128m;
  ssl_session_timeout        5m;
}

Create the puppet configuration file /etc/puppet/puppet.conf:

[main]

[agent]
  server = puppet.example.com

[master]
  certname = puppet.example.com

Turn puppet master off as it doesn’t need to run standalone:

# chkconfig puppetmaster off

Run a stand-alone puppet master to generate/sign certs etc.

# puppet master --no-daemonize --verbose
info: Creating a new SSL key for puppet.example.com
info: Creating a new SSL certificate request for puppet.example.com
info: Certificate Request fingerprint (md5): 04:AA:81:9E:49:B9:CA:2B:FD:D0:32:1B:69:CC:3E:B4
notice: puppet.example.com has a waiting certificate request
notice: Signed certificate request for puppet.example.com
notice: Removing file Puppet::SSL::CertificateRequest puppet.example.com at '/etc/puppet/ssl/ca/requests/puppet.example.com.pem'
notice: Removing file Puppet::SSL::CertificateRequest puppet.example.com at '/etc/puppet/ssl/certificate_requests/puppet.example.com.pem'
notice: Starting Puppet master version 2.7.11

Hit Ctrl+c to stop the stand-alone puppet master. You can see above that this has created a SSL key and certificate request, then signed this certificate request.

Add an nginx user:

# adduser nginx

Enable nginx

# chkconfig nginx on

Make sure everything looks good:

# service nginx configtest

If so, away you go:

# service nginx start

Now test a puppet agent run on the master:

# puppet agent --server puppet --onetime --no-daemonize --verbose --noop
info: Caching catalog for puppet.example.com
info: Applying configuration version '1330615281'
notice: Finished catalog run in 0.04 seconds

One drawback of using nginx and passenger to front your Puppet master is that when there is a passenger upgrade, you will need to recompile nginx against the new passenger version and build a new RPM. Fortunately, because you are now running puppet and have been converted to fpm, this should be a trivial task, and not something you will need to do very often.

Puppet  Nginx  Ruby 
 

有趣的insert死锁

By Chao Nie at 20 July 2013

有趣的insert死锁

来自:http://blog.csdn.net/gtuu0123/article/details/5651493

昨天看到一个很有意思的死锁,拿来记录下:

环境:deadlock on
事务隔离级别:read commited

表结构:

root@test 08:34:01>show create table lingluo\G
*************************** 1. row ***************************
	   Table: lingluo
Create Table: CREATE TABLE `lingluo` (
  `a` int(11) NOT NULL DEFAULT '0',
  `b` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  `d` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`),
  UNIQUE KEY `uk_bc` (`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)

session 1:

root@test 08:45:51>select * from lingluo;
+--------+------+------+------+
| a      | b    | c    | d    |
+--------+------+------+------+
|      1 |    2 |    3 |    4 |
|    500 |  100 |  200 |   43 |
|   1000 |   10 |   20 |   43 |
|  10001 |   21 |   21 |   32 |
| 100202 |  213 |  213 |  312 |
| 100212 |  214 |  214 |  312 |
+--------+------+------+------+
6 rows in set (0.00 sec)

root@test 08:46:38>begin;
Query OK, 0 rows affected (0.00 sec)

root@test 08:47:04>insert into lingluo values(100213,215,215,312);
Query OK, 1 row affected (0.00 sec)

session 2:

root@test 08:46:02>begin;
Query OK, 0 rows affected (0.00 sec)

root@test 08:47:20>insert into lingluo values(100214,215,215,312);
Query OK, 1 row affected (12.77 sec)

session3:

root@test 08:46:24>begin;
Query OK, 0 rows affected (0.00 sec)

root@test 08:47:23>insert into lingluo values(100215,215,215,312);

session 1 rollback前:

---TRANSACTION 4F3D6F33, ACTIVE 3 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 376, 1 row lock(s), undo log entries 1
MySQL thread id 18124715, OS thread handle 0x7fea34912700, query id 1435660081 localhost root update
insert into lingluo values(100215,215,215,312)
------- TRX HAS BEEN WAITING 3 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6F33 lock mode S waiting
------------------
TABLE LOCK table `test`.`lingluo` trx id 4F3D6F33 lock mode IX
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6F33 lock mode S waiting
---TRANSACTION 4F3D6D24, ACTIVE 5 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 376, 1 row lock(s), undo log entries 1
MySQL thread id 18124702, OS thread handle 0x7fe706fdf700, query id 1435659684 localhost root update
insert into lingluo values(100214,215,215,312)
------- TRX HAS BEEN WAITING 5 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock mode S waiting
------------------
TABLE LOCK table `test`.`lingluo` trx id 4F3D6D24 lock mode IX
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock mode S waiting
---TRANSACTION 4F3D4423, ACTIVE 33 sec
2 lock struct(s), heap size 376, 1 row lock(s), undo log entries 1
MySQL thread id 18124692, OS thread handle 0x7fe73c89a700, query id 1435651549 localhost root
TABLE LOCK table `test`.`lingluo` trx id 4F3D4423 lock mode IX
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D4423 lock_mode X locks rec but not gap

/**

session1 上的转为显式锁:lock_mode X locks rec but not gap

session2 等待的锁:lock mode S waiting

session3 等待的锁:lock mode S waiting

**/

session1 rollback

session2 插入成功

session3 ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

这个时候show engine innodb status:

5 lock struct(s), heap size 1248, 3 row lock(s), undo log entries 1
MySQL thread id 18124702, OS thread handle 0x7fe706fdf700, query id 1435659684 localhost root
TABLE LOCK table `test`.`lingluo` trx id 4F3D6D24 lock mode IX
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock mode S
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock mode S
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock_mode X insert intention
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock mode S locks gap before rec

死锁信息:

------------------------
LATEST DETECTED DEADLOCK
------------------------
130701 20:47:57
*** (1) TRANSACTION:
TRANSACTION 4F3D6D24, ACTIVE 13 sec inserting, thread declared inside InnoDB 1
mysql tables in use 1, locked 1
LOCK WAIT 4 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
MySQL thread id 18124702, OS thread handle 0x7fe706fdf700, query id 1435659684 localhost root update
insert into lingluo values(100214,215,215,312)
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6D24 lock_mode X insert intention waiting
*** (2) TRANSACTION:
TRANSACTION 4F3D6F33, ACTIVE 11 sec inserting, thread declared inside InnoDB 1
mysql tables in use 1, locked 1
4 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
MySQL thread id 18124715, OS thread handle 0x7fea34912700, query id 1435660081 localhost root update
insert into lingluo values(100215,215,215,312)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6F33 lock mode S
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 3351 page no 4 n bits 80 index `uk_bc` of table `test`.`lingluo` trx id 4F3D6F33 lock_mode X insert intention waiting
*** WE ROLL BACK TRANSACTION (2)

原因:

s1 , type_mode=1059 //s2为s1转换隐式锁为显式锁

s2, type_mode=1282 //检查重复键,需要加共享锁,被s1 block住,等待S锁

s3, type_mode=1282 // 被s1 block住,等待S锁

s1, type_mode=547 //s1回滚,删除记录,lock_update_delete锁继承,

s2, type_mode=546 //创建s锁 LOCK_GAP LOCK_REC LOCK_S
s3, type_mode=546 //创建s锁 LOCK_GAP LOCK_REC LOCK_S
s2, type_mode=2819 // LOCK_X LOCK_GAP LOCK_INSERT_INTENTION
s3, type_mode=2819 // LOCK_X LOCK_GAP LOCK_INSERT_INTENTION

当s1回滚后,s2和s3获得s锁,但随后s2和s3又先后请求插入意向锁,因此锁队列为:

s2(S GAP)<—s3(S GAP)<—s2(插入意向锁)<–s3(插入意向锁) s3(s锁),s2(x锁),s3(x锁)形成死锁。

这样的死锁不光出现在unique key,还包括primary key(unique key的特殊形式)

印风的博客里有更详细的代码级别的记录,有兴趣的可以看下

另外如果:deadlock off的话,即使session 1rollback了,session 2和session 3还是处于等待的状态,除非超过了innodb_lock_wait_timeout的时间,报

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

CPU相关概念

By Chao Nie at 29 March 2013

What is the difference between a processor, a chip, a socket, and a core?

来自:http://kb.iu.edu/data/avfb.html

Following are brief definitions for common terms related to supercomputers:

Cores

Recent developments in computational architecture can lead to confusion concerning what a microprocessor is. Since the advent of multi-core technology, such as dual-cores and quad-cores, the term “processor” has been used to describe a logical execution unit or a physical chip. A multi-core chip may have several cores. With the advent of multi-core technology, the term “processor” has become context-sensitive, and is largely ambiguous when describing large multi-core systems. Essentially a core comprise a logical execution unit containing an L1 cache and functional units. Cores are able to independently execute programs or threads. Supercomputers are listed as having thousands of cores.

Chips

A chip refers to a physical integrated circuit (IC) on a computer. A chip in the context of this document refers to an execution unit that can be single- or multi-core technology.

Sockets

The socket refers to a physical connector on a computer motherboard that accepts a single physical chip. Many motherboards can have multiple sockets that can in turn accept multi-core chips.

Processes

A process is an independent program running on a computer. A process has a full stack of memory associated for its own use, and does not depend on another process for execution. MPI (Message Passing Interface) processes are true processes because they can run on independent machines or the same machine.

Thread

A thread is essentially a process that does not have a full stack of memory associated for it. The thread is tied to a parent process, and is merely an offshoot of execution. Typically thread processes must run on the same computer, but can execute simultaneously on separate cores of the same node. OpenMP parallelism uses threads for child processes.

Hyper-threading

Hyper-threading is an Intel technology that originally preceded multi-core systems, and was used to make a single core appear logically as multiple cores on the same chip. Intel abandoned hyper-threading briefly during the advent of multi-core processors but reintroduced the technology in 2008. Since then, Intel has used it extensively to improve the performance of parallel computations in its multi-core processors. Hyper-threading improves performance by sharing the computational workload between multiple cores whenever possible, allowing the operating system to schedule more than one process at a time. For more, see Intel Hyper-Threading Technology.

N-ways

Multi-core compute nodes can be described by the number of execution units, or cores. A computer with 8 cores would be described as an 8-way node. This machine can have 8 independent processes running simultaneously. A 32-core system would be called a 32-way node.

Processor

As explained above, a processor could describe either a single execution core or a single physical multi-core chip. The context of use will define the meaning of the term.

This document was developed with support from National Science Foundation (NSF) grant OCI-1053575. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.

This is document avfb in domains all and xsede-all. Last modified on March 08, 2013.

Linux下如何识别物理cpu个数,几个核,是超线程还是多核心

来自:http://www.83blog.com/xeon-cpu-core.html

判断依据:

1.具有相同core id的cpu是同一个core的超线程。
2.具有相同physical id的cpu是同一颗cpu封装的线程或者cores。

英文版:

1.Physical id and core id are not necessarily consecutive but they are unique. Any cpu with the same core id are hyperthreads in the same core.
2.Any cpu with the same physical id are threads or cores in the same physical socket.

实例:

LunarPages的CPU信息:

processor      : 0
vendor_id      : GenuineIntel
cpu family     : 15
model          : 4
model name     : Intel(R) Xeon(TM) CPU 3.00GHz
stepping       : 3
cpu MHz        : 3000.881
cache size     : 2048 KB
physical id    : 0
siblings       : 2
core id        : 0
cpu cores      : 1
fdiv_bug       : no
hlt_bug        : no
f00f_bug       : no
coma_bug       : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 5
wp             : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips       : 6006.73
processor      : 1
vendor_id      : GenuineIntel
cpu family     : 15
model          : 4
model name     : Intel(R) Xeon(TM) CPU 3.00GHz
stepping       : 3
cpu MHz        : 3000.881
cache size     : 2048 KB
physical id    : 0
siblings       : 2
core id        : 0
cpu cores      : 1
fdiv_bug       : no
hlt_bug        : no
f00f_bug       : no
coma_bug       : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 5
wp             : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips       : 5999.40
processor      : 2
vendor_id      : GenuineIntel
cpu family     : 15
model          : 4
model name     : Intel(R) Xeon(TM) CPU 3.00GHz
stepping       : 3
cpu MHz        : 3000.881
cache size     : 2048 KB
physical id    : 3
siblings       : 2
core id        : 3
cpu cores      : 1
fdiv_bug       : no
hlt_bug        : no
f00f_bug       : no
coma_bug       : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 5
wp             : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips       : 5999.08
processor      : 3
vendor_id      : GenuineIntel
cpu family     : 15
model          : 4
model name     : Intel(R) Xeon(TM) CPU 3.00GHz
stepping       : 3
cpu MHz        : 3000.881
cache size     : 2048 KB
physical id    : 3
siblings       : 2
core id        : 3
cpu cores      : 1
fdiv_bug       : no
hlt_bug        : no
f00f_bug       : no
coma_bug       : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 5
wp             : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips       : 5999.55

显示4个逻辑CPU,通过physical id ,前面两个逻辑cpu的相同,后面两个的相同,所以有两个物理CPU。前面两个的 core id相同,后面的两个core ID相同,说明这两个CPU都是单核。也就是说两个单核cpu,启用了超线程技术。

通过intel的cpu的参数可以初步判断 使用的是两个 Xeon奔腾4CPU 。

如何获得CPU的详细信息:

cat /proc/cpuinfo

用命令判断几个物理CPU,几个核等:

逻辑CPU个数:

cat /proc/cpuinfo | grep “processor” | wc -l

物理CPU个数:

cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l

每个物理CPU中Core的个数:

cat /proc/cpuinfo | grep “cpu cores” | wc -l

是否为超线程?

如果有两个逻辑CPU具有相同的”core id”,那么超线程是打开的。

每个物理CPU中逻辑CPU(可能是core, threads或both)的个数:

cat /proc/cpuinfo | grep “siblings”

其他特征:

目前intel新的多核心cpu都会在后面显示具体的型号数字,例如:

model name        : Intel(R) Xeon(R) CPU           X3230  @ 2.66GHz

说明是 Xeon 3230的cpu,而不显示型号的具体数字的,大部分都是奔腾的CPU

很多主机商都骗人,用奔腾的cpu,却说是多核心的CPU。

探针看到的数据:

类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB
类型:Intel(R) Xeon(TM) CPU 2.80GHz 缓存:1024 KB

没有具体的型号,缓存1M,一般都是奔腾系列的cpu,或者是intel假双核的cpu,具体要根据上面说的去判断。新的多核心cpu都能看到具体的型号。

另外多核心的xeon的CPU,一般主频都不高,达到2.8和3.0的只有很少的几个高端CPU型号,一般主机商不会用这么好的。

CPU 
 
1/20 - 98 Posts
Next Page
About   |   Fork me on GitHub  
Theme made by olivida
VERSION: 0.3.0
♥ Do have a faith in what you're doing.