2016年8月17日 星期三

[elasticsearch] high performance elasticsearch configuration 設計配置


底下列出一份經過tuning 過的 elasticsearch configuration

/etc/elasticsearch/elasticsearch.yml

  • cluster.name: estic12
    • which is used to discover and auto-join other nodes
  • node.name: "pcnode1"
    • You may also want to change the default node name for each node to something like the display hostname. By default Elasticsearch will randomly pick a Marvel character name from a list of around 3000 names when your node starts up
  • node.master: true
  • node.data: false
    • dedicated master nodes
  • path.data: /spare3
    • The location of the data files of each index / shard allocated on the node. Can hold multiple locations.
    • Note, there are no multiple copies of the same data, in that, its similar to RAID 0. Though simple, it should provide a good solution for people that don’t want to mess with RAID. Here is how it is configured:
      • path.data: /mnt/first,/mnt/second
      • Or the in an array format:
        • path.data: ["/mnt/first", "/mnt/second"]
  • discovery.zen.ping.multicast.enabled: false
  • discovery.zen.ping.unicast.hosts: ["tic12-a42.trendmicro.com", "tic12.trendmicro.com", "tic12-a45.trendmicro.com"]
    • The zen discovery is the built in discovery module for elasticsearch and the default. It provides both multicast and unicast discovery as well being easily extended to support cloud environments.

  • threadpool.bulk.type: fixed
  • threadpool.bulk.size: 100
  • threadpool.bulk.queue_size: 320
    • For bulk operations, defaults to fixed size # of available processors. queue_size 50.
    • The fixed thread pool holds a fixed size of threads to handle the requests with a queue (optionally bounded) for pending requests that have no threads to service them.

  • discovery.zen.minimum_master_nodes: 2 #(es_node_num)/2 +1
    • sets the minimum number of master eligible nodes that need to join a newly elected master in order for an election to complete and for the elected node to accept its mastership.
  • indices.memory.index_buffer_size: 30%
    • The indexing buffer setting allows to control how much memory will be allocated for the indexing process.
    • accepts either a percentage or a byte size value. It defaults to 10%, meaning that 10% of the total memory allocated to a node will be used as the indexing buffer size.
  • index.translog.flush_threshold_ops: 50000
    • Each shard has a transaction log or write ahead log associated with it. It allows to guarantee that when an index/delete operation occurs, it is applied atomically, while not "committing" the internal Lucene index for each request.
    • After how many operations to flush.
  • index.refresh_interval: 30s
    • The async refresh interval of a shard.
    • How often to perform a refresh operation, which makes recent changes to the index visible to search.

2016年7月26日 星期二

[git] 開發中 rebase 拉取新的程式碼



開發中不想把修改的部份 commit ,怎麼使用 rebase 抓取新的程式碼


  • 把修改的檔案加到 stage

    git add . 

          git commit -m 'add to stash'


  • 使用 pull --rebase 拉取新的程式碼

    git pull --rebase origin master 


途中可能要解決一些 conflict 問題


  • 最後

    git reset HEAD~1 
把自己的最後一次 commit reset 掉,並保留更新的內容。






2016年7月13日 星期三

[docker] run s3 on Ceph in docker containers 在 docker 來執行 s3 ceph



怎麼使用 docker 來執行 ceph 呢?

ceph 官方有提供一個可以很快搭建開發環境的 docker container

ceph-docker/ceph-releases/jewel/ubuntu/14.04/demo at master · ceph/ceph-docker
https://github.com/ceph/ceph-docker/tree/master/ceph-releases/jewel/ubuntu/14.04/demo


先 ifconfig 看一下目前自己ip

docker run -d --net=host -v /etc/ceph:/etc/ceph -e MON_IP=10.1.193.59 -e CEPH_PUBLIC_NETWORK=10.1.193.0/24 ceph/demo

# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
662e2c899f4c        ceph/demo           "/entrypoint.sh"    35 minutes ago      Up 35 minutes                           tender_carson

為了執行 s3 ceph 所以使用  radosgw 來建立user 取得 access_key 與 secret_key

 # radosgw-admin user create --uid="pc" --display-name="pc"          
2016-07-13 12:08:14.244392 7f1bb4069900  0 RGWZoneParams::create(): error creating default zone params: (17) File exists
{
    "user_id": "pc",
    "display_name": "pc",
    "email": "",
    "suspended": 0,
    "max_buckets": 1000,
    "auid": 0,
    "subusers": [],
    "keys": [
        {
            "user": "pc",
            "access_key": "F47DG9NWH4HNMZ06EAYD",
            "secret_key": "9FdywQQltiJHrHuOwfRtDE0HVc6exIAJZ1PHjLDa"
        }
    ],
    "swift_keys": [],
    "caps": [],
    "op_mask": "read, write, delete",
    "default_placement": "",
    "placement_tags": [],
    "bucket_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "user_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "temp_url_keys": []
}


可以撰寫一個簡單的s3 程式

Python S3 Examples — Ceph Documentation 

import boto
import boto.s3.connection
access_key = 'put your access key here!'
secret_key = 'put your secret key here!'

conn = boto.connect_s3(
        aws_access_key_id = access_key,
        aws_secret_access_key = secret_key,
        host = 'objects.dreamhost.com',
        #is_secure=False,               # uncomment if you are not using ssl
        calling_format = boto.s3.connection.OrdinaryCallingFormat(),
        )

conn.create_bucket('my-new-bucket')

for bucket in conn.get_all_buckets():
    print bucket
這樣就可以看到有create bucket了

2016年7月1日 星期五

[elasticsearch]Rollover API and Shrink API 更好的管理 time-based event data Elastic Stack Release - 5.0.0-alpha4


Elastic Stack Release - 5.0.0-alpha4 令人振奮的提供了兩個對於 time-based index 更友善的API 。

New Rollover API and Shrink API makes managing indices for time-based event data much easier



Rollover Index


Rollover Index | Elasticsearch Reference [master] | Elastic
https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html

The rollover index API rolls an alias over to a new index when the existing index is considered to be too large or too old.

可以使用這個 rollover api 定義時間(max_age)或者是  資料的筆數 (max_docs) ,當條件符合時,就會根據規則自己建立新的 index 。



PUT /logs-0001 
{
  "aliases": {
    "logs_write": {}
  }
}

POST logs_write/_rollover 
{
  "conditions": {
    "max_age":   "7d",
    "max_docs":  1000
  }
}

 1.  建立一個新的 index 並指定 alias 為 logs_write
 2.  設定 當 index 被建立了七天,或是文件數超過 1000 就會建立新的 index 。並且命名為 logs-0002

這裡是 POST 的 response 
{
  "old_index": "logs-0001",
  "new_index": "logs-0002",
  "rolled_over": true, 
  "dry_run": false, 
  "conditions": { 
    "[max_age: 7d]": false,
    "[max_docs: 1000]": true
  }
}


index naming 的規格就是 使用 - 分隔 ,後面的數字會自行遞增。


Shrink index API

Shrink Index | Elasticsearch Reference [master] | Elastic
https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html
另外一個 api 就是 shrink api
The shrink index API allows you to shrink an existing index into a new index with fewer primary shards.

如果你想變更 primary shard 的設定,可以去自動的去幫你建立一個新的 index 。


Shrinking works as follows:
  • First, it creates a new target index with the same definition as the source index, but with a smaller number of primary shards.
  • Then it hard-links segments from the source index into the target index. (If the file system doesn’t support hard-linking, then all segments are copied into the new index, which is a much more time consuming process.)
  • Finally, it recovers the target index as though it were a closed index which had just been re-opened.

這邊有個值得注意的地方就是shrink 過的index 每個shard 不能超過 2,147,483,519 documents  。


  • The index must not contain more than 2,147,483,519 documents in total across all shards that will be shrunk into a single shard on the target index as this is the maximum number of docs that can fit into a single shard.

首先,要先確定cluster 的 health 是 green , index 要被改成 read only ,且要把index的所有shard 搬到同一台node 上才能進行。
這兩個要求可以透過下面的 request 達到。
index.blocks.write 設成 true 是還是允許 delete 的這種改變metadata的操作。

PUT /my_source_index/_settings
{
  "settings": {
    "index.routing.allocation.require._name": "shrink_node_name", 
    "index.blocks.write": true 
  }
}


當 shard 搬移完成後,可以就可以使用 shrink api

POST my_source_index/_shrink/my_target_index


要觀察這些狀態,可以使用   > curl -XGET 'localhost:9200/_cat/recovery?v'

elasticsearch 加上了這兩個 api ,
對於 index time base 的資料的使用者,方便性又更加的提升了。


2016年6月27日 星期一

[武術] 160627 (一) 太極拳能養生但要練得正確


今天晚上參加了永和社大的一場演講,
是由 鄭子太極拳名家 吳嘯老師的課。

吳老師有講解他的習拳心得,跟示範一些勁法與拳架的配合。

印象很深的點,在於 他放了葉問的圖,來講落跨。
甚至示範說,跨往前推自然就發勁。

重心轉移發勁的概念,跟溫師兄所說的方式相同,不過這次沒有機會體驗一下吳老師的勁法。

以前在練拳時,老師不讓他們當場做筆記,就是要聽課時能夠集中注意力。

方法掌握,就能在拳架上面配合。

特別強調鳥伸

很多原理講明了,其實都很容易做出來。

還有提到怎麼解析,鄭子的雙按,與打拳的形式。
怎麼形成一個立圓。

前手不動,後手動,甚至整個腰跨作用。

開胸 就像是水壩一樣 u 才能擋住力量
肘如果開一點,別人來力,往後一點,也不會受到影響。但是你外表也涵胸,而不是先開胸,在往內涵胸,就會被發出去。

值得注意的是,吳老師發勁的身形與站姿,開胸與重心鳥伸前移,前手不動後手發。



練對太極才能養生2016-06-27 ,其他運動類, 免費課程/活動, - BeClass 線上報名系統 Online Registration Form
http://www.beclass.com/rid=193a05f5756e28c4dabc
永和社大: 開放的一堂課
主題: 太極拳能養生但要練得正確
時間 : 6月27日(星期一)晚上7時30分
地點 : 福和國中 大韻律教室
鄭子太極拳是台灣流傳最普遍的太極拳,其鬆柔舒展更有助養生。但若僅由學習外顯的「拳架」,而未能掌握鄭子太極拳精華的「內涵」。不僅事倍功半,也對養生效益大打折扣。講座將揭開鄭曼青太極拳的奧秘,並配合解說與動作示範,效果立能體驗。內容不是一般習見的拳架解說,有心拳友絕不能錯過。
【參加者贈送:鄭曼青大師拳劍勁法光碟】
新北市永和區永利路71號


虛實分清 根本基礎
重心與圓
體用合一

不失重心 勁源
丹田是核心 主宰於腰
節節貫穿 筋張是賴

落跨
如何步隨身換

迷時師渡 悟時自渡
拆開練



2016年6月20日 星期一

[電影] 奮鬥 被人嘲笑的夢想 就越有實踐的價值


很難想像我在多年後,再重拾 奮鬥 這個系列。

《奮鬥》是導演馬偉豪執導的一部電影,該片根據同名小說《奮鬥》改編而成,由李晨,董璇等主演,該片定於2011年4月2日全國上映。 該片描述了一群善良、勇敢與堅持的年輕人勇於奮鬥,並最終在生活中找到自己位置的故事。

奋斗(2011年马伟豪导演电影)_百度百科
http://baike.baidu.com/subview/54021/5450252.htm
到現在還很有印象的 , hua 當年在北京,跟我說的趙寶剛執導的《奮鬥》《我的青春誰做主》《北京青年》被稱為“青春三部曲”。 

奮鬥的電視劇我應該也還沒補齊,這次就從我的青春誰作主開始回味一下。

看到奮鬥的場景與對白,最一直與最近在內心深處的問題相互回應。
當年,說下的那些夢想,今日,我要實踐下了幾分。

說真的,挺還念之前在北京的日子。



奋斗 - 在线观看 - 电影 - 乐视视频

  • 奮鬥
    • 被人嘲笑的夢想 就越有實踐的價值
    • 來日方長 海闊天空
出现在电影《奋斗》中的咖啡馆——苏州魔方LOFT_视频在线观看 - 56.com
乐视直播-乐视轮播台在线观看-乐视直播频道_轮播台-乐视网
《奋斗》外景地、拍摄地点汇总,非常全,有空实地考察看看 – 【人人分享-人人网】
魔方LOFT | MOFUN, your lounge LOFT!
http://www.loftmofun.com/fendou.htm

[mysql] how to get table record size 取得每筆資料的大小


要怎麼取得每一筆reocrd 在 database的 size ,
除了可以查看 schema 外,
更實際的作法可以觀看 table status

把 data_length 加上 index_length 就可以得到 table 的 size
在把它除以多少筆record 即可得到每一筆 record 需要多少 bytes 。


mysql> show table status\G

*************************** 3. row ***************************
           Name: task_target
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 7
 Avg_row_length: 2340
    Data_length: 16384
Max_data_length: 0
   Index_length: 16384
      Data_free: 3373268992
 Auto_increment: 8
    Create_time: 2016-06-14 09:36:33
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options:
        Comment:



(Data_length + Index_length ) / rows ---> 每個 row 的 size bytes


(Data_length + Index_length ) / rows /1024 /1024 ---> 每個 row 的 size bytes MB


MySQL :: MySQL 5.7 Reference Manual :: 14.7.5.36 SHOW TABLE STATUS Syntax
http://dev.mysql.com/doc/refman/5.7/en/show-table-status.html

2016年6月8日 星期三

[python] SQLAlchemy session 的 flush 與 commit 的區別


 SQLAlchemy session 的 flush 與 commit 的區別

flush 把sql操作提交到 database 的 memory 去 ,可以使用roll back
整個 transaction 要等到 commit 了 database 才會生效把結果 寫到disk


sqlalchemy里flush与commit区别 - Alan Matrix
python - SQLAlchemy 中的使用 flush() 和 commit() 有什么区别 - SegmentFault
https://segmentfault.com/q/1010000000698181

2016年6月3日 星期五

[ambari] how to reset ambari admin password



#psql -U ambari ambari

 Enter password 'bigdata'

In psql:

update ambari.users set user_password='538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00' where user_name='admin'

 Quit psql

 Run 'ambari-server restart'

This will reset the admin account back to the password of 'admin'

[vagrant] Device eth1 does not seem to be present, delaying initialization.


$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) eth0
2) vmnet8
3) vmnet1
4) docker0
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
    default: Which interface should the network bridge to?     default: Which interface should the network bridge to?     default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

ARPCHECK=no /sbin/ifup eth1 2> /dev/null

Stdout from the command:

Device eth1 does not seem to be present, delaying initialization.


Stderr from the command:

================
sol

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules

原本vm 中的udev  persistent network device udev rules 發生衝突把他刪除就會重新產生



2016年5月23日 星期一

[mac] sublime_diagram_plugin in setup raise Exception('No working processors found!') Exception: No working processors found! 解決方式


使用 Sublime + PlantUML 的 sublime_diagram_plugin 可能會出現下面問題

s/jvantuyl-sublime_diagram_plugin-034b659/diagram/__init__.py", line 49, in setup raise Exception('No working processors found!') Exception: No working processors found!

後來發現是沒有安裝 graphviz

#brew install graphviz

就解決了 (ps 要有java env)

使用 Sublime + PlantUML 高效地画图 - 简书
http://www.jianshu.com/p/e92a52770832/comments/1064420

2016年5月13日 星期五

[linux] ffmpeg 去除影片聲音


怎麼使用 ffmpeg 去除影片檔的聲音呢?

ffmpeg -i input.mp4 -vcodec copy -an ouput.mp4


各個 options 的說明如下

       -i filename (input)

           input file name 輸入的檔案
       -vcodec codec (output)

           Set the video codec. This is an alias for "-codec:v".
codec

           is the name of a decoder/encoder or a special value "copy" (output only) to indicate that the stream is not to be re-encoded.

       -an (output)

           Disable audio recording.


2016年5月12日 星期四

[java] mac 更換 JDK java 版本 /usr/libexec/java_home


1. 先看一下目前使用的 JDK 版本

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.0_91, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
    1.7.0_60, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home


ps  .直接上Oracle 網站下載 mac java dmg 檔案 安裝



2.  編輯一下 ~/.bashrc 內的 JAVA_HOME 位置

export JAVA_HOME=`/usr/libexec/java_home -v1.8`

2016年5月3日 星期二

[健康講座] 160409 教您呼吸保健康,有氧活出生命力 氧樂多


100台北市中正區紹興北街3號
教您呼吸保健康,有氧活出生命力

講座簡介:
1. 萬惡之源-口呼吸,您呼吸對了嗎 ?!
2. 氧氣不可或缺,讓您全身充滿氧氣好活力。

講座時間:4/9(六)18:00 - 20:00
講座地點:台北市紹興北街3號4樓(捷運善導寺6號出口附近)

趙哲暘 醫師

氧樂多牙醫診所|不拔牙矯正、牙周活氧治療、安全植牙、全人治療

本來過年前就有報名這場講座,後來因為時間安排skip掉預約。
4月終於再次有機會參加了。

第一次知道趙醫師,是從健康2.0跟一篇文章上看來了。
我們都知道呼吸很重要,但是怎麼都沒有人再講比較好的呼吸方式。
一般來說,都是去練習氣功,但是,滿多人練習完氣功還是對呼吸不得要領。

趙醫師從醫學的角度來說呼吸。
基本上來說,這裡的呼吸就是使用肺呼吸。
過度提倡腹式呼吸,結果大家變成不會呼吸。
(這裡不討論是否有真傳的氣功)
呼吸在醫學上來說,就是透過鼻子吸入空氣,然後再肺部做氣體的交換。

節錄一段一般的解釋:
  吸氣時,由於胸部肋骨上升與外張,以及橫膈膜上肌肉收縮,使胸腔底部向下移,以致胸腔擴大,肺部擴張。肺體積擴大,因而肺(肺泡)內壓力降低,空氣即自外經呼吸道進入肺泡進行氣體交換。吸氣之後又由於肋骨下降和橫膈膜肌肉舒張,因而胸腔底部上升,胸腔隨即縮小,使胸腔內的壓力增大,肺臟受壓縮,肺泡裏的空氣被擠出去,即完成了呼氣。吸氣和呼氣動作持續不斷的交互進行,肺臟便可維持正常的氣體交換。一般正常成年人於安靜狀態下之呼吸,每分鐘約16-18次,劇烈運動或工作後,呼吸次數則會顯著增加。

  • 排靜電

1.發生呼吸氣體交換作用時,O2及CO2分子必先溶於水中,始能通過潤濕的細胞膜而擴散,故呼吸器官都要具有濕潤的皮膜,並盡量擴大其表面積,才能增進氣體交換速率
2.呼吸氣體交換是利用氣體濃度(氣體分壓)不同而完成擴散交換,其交換場所,一在肺泡,另一在組織細胞:
(1)外呼吸:肺泡與肺泡微血管間的氣體交換,使缺氧血變成充氧血,發生於小循環之過程中,又稱為肺呼吸。此時O2進入肺微血管,CO2則送至肺泡呼出肺
(2)內呼吸:各組織細胞與微血管間的氣體交換,使充氧血變成缺氧血,發生於大循環過程中,又稱組織呼吸。此時O2進入組織細胞,CO2則進入血液中運走

呼吸系統

裏面有個解釋,趙醫師特別也提到呼氣的重要。
(如果你練氣功,也是不能只有一天就練那一兩個小時,就像一個24h工廠,只運作一兩小時一樣。)
呼氣時,二氧化碳才能有作用,才能交換。二氧化碳就可以使血管擴張。
所以趙醫師建議的練習是吸呼都是儘量五秒,也就是一分鐘六到八次呼吸。

這個世紀整個大氣的含氧量,已經下降,加上人口變多,所以每個人能夠吸到的氧氣又更少,所以更要好好呼吸。
(高壓氧的摹擬訓練可以使用養樂多的小吸管,可以參考其他資料)
  • 微笑 抬頭腰打直 深呼吸
有一些簡單的放鬆動作
  • 含水快速扣齒  舒緩咀嚼肌群 強化口腔扎肌 (20次)
  • 手指輕敲太陽穴 舒緩囁肌 由上而下手指輕敲太陽穴 (20次)
  • 手指壓揉臉頰肌肉 舒緩咬肌 由顴骨往下班角手指頭壓揉臉頰咬肌 (10次)
  • 捲舌張口到最大 舒緩咬肌與外翼肌 每次5秒 每天 20次 將嘴巴打開至感覺耳朵有伸張 (10次)
  • 訓練舌骨前肌群穩定下顎 頭先上仰 眼睛往上方看 下巴再往上方伸出 繃緊下巴內緣肌肉 5秒 (10次)
  • 穩定下顎 推揉後二腹肌 (10次)
  • 舒緩枕骨與頸椎 雙手放於枕骨與頸椎 輕推顱骨 (5分鐘)

其他的一些簡記

  • 運動模擬發燒 稍微出汗即可
  • 律動 戰舞 原住民的舞蹈
  • 慢跑跳繩快步走
  • 律動跟有氧運動
  • 讓該休息的細胞勞累 過勞
  • 電位醫學
    • ~50 細胞再生 30癌症
    • 酸鹼 血氧
    • 電位要到-20
    • -25成人理想電位
  • 兩種老死
    • 植物人慢慢老死
    • 癌症快快老死
  • 氧氣接地 情緒紓解 (看山看海)
  • 交感神經異地而處
  • 供氧增加 耗氧減少
  • 呼吸道 不要急
  • 睡前二十分墊著腰
  • 曬太陽接地
  • 視野開心也開
  • 放電採綠地喝水
  • 關心自己跟別人
  • 啟動大腦前額葉
  • 銀布

2016年5月2日 星期一

避免數值超過 64bit long 的長度跟overflow 溢出 & 0x7fffffffffffffff

要避免數值溢出
使用 mask 的方式來避免

 a & 0x7fffffffffffffff

0x7fffffffffffffff 為64bit long 下 的最大值 ,也就是使用bit 表示 你會看到一串 1111...1111

使用 & 來做 mask , 當位數限制在 long long 的長度 ,才允許留下來。

如此就可以做到避免數值超過 64bit long 的長度跟overflow 溢出

只要使用 & 0x7fffffffffffffff 即可