<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tossapon Nuanchuay on Medium]]></title>
        <description><![CDATA[Stories by Tossapon Nuanchuay on Medium]]></description>
        <link>https://medium.com/@tossaponnuanchuay?source=rss-9cc26d61f9a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pzeYUWRDiAk_Zw_g4mwhUw.jpeg</url>
            <title>Stories by Tossapon Nuanchuay on Medium</title>
            <link>https://medium.com/@tossaponnuanchuay?source=rss-9cc26d61f9a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:37:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tossaponnuanchuay/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[หาค่า p ที่สนใจ เมื่อทราบค่า P(n=x) ของ event เมื่อความน่าจะเป็น เป็นแบบ Geometric distribution]]></title>
            <link>https://medium.com/@tossaponnuanchuay/%E0%B8%AB%E0%B8%B2%E0%B8%84%E0%B9%88%E0%B8%B2-p-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%AA%E0%B8%99%E0%B9%83%E0%B8%88-%E0%B9%80%E0%B8%A1%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%97%E0%B8%A3%E0%B8%B2%E0%B8%9A%E0%B8%84%E0%B9%88%E0%B8%B2-p-n-x-%E0%B8%82%E0%B8%AD%E0%B8%87-event-%E0%B9%80%E0%B8%A1%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%99%E0%B9%88%E0%B8%B2%E0%B8%88%E0%B8%B0%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99-%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B9%81%E0%B8%9A%E0%B8%9A-geometric-distribution-2f7ecf2ffa43?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f7ecf2ffa43</guid>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Sun, 04 Aug 2019 15:45:57 GMT</pubDate>
            <atom:updated>2019-08-04T15:46:52.307Z</atom:updated>
            <content:encoded><![CDATA[<h3>หาค่า p ที่สนใจ เมื่อทราบค่า P(x=n) ของ event เมื่อความน่าจะเป็น เป็นแบบ Geometric distribution</h3><p>ช่วงนี้มีโอกาสทำงานด้าน metrics/measurement ของ tests มีเรื่องน่าสนใจอยู่หลายเรื่อง. ประเด็นที่น่าสนใจคือ tests ของเรามีการทำ retry เป็นจำนวน n ครั้ง เพื่อทำให้ release pipeline ทำงานได้เร็วขึ้น. ไม่ต้องไปเริ่มต้นใหม่เพียงเพราะ false positive test result.</p><p>ในบทความนี้ จะไม่พูดถึงประสิทธิภาพของการทดสอบ เพราะยิ่งการทำ retry มากเท่าไหร เรายิ่งไม่รู้เลยว่าเป็น target’s source code กับ test source code, อะไรทำงานผิดพลาดกันแน่</p><p>เราเริ่มเก็บข้อมูลการทำ retry ของแต่ละข้อการทดสอบ เพื่อนำมาวิเคราะห์และนำไปจัดการแก้ปัญหาต่อไป แต่ในมุมมองนี้ การแสดงค่าจำนวนการทำ retry จะทำให้เรามองไม่เห็นประสิทธิภาพของข้อทดสอบ เช่น จำนวนการ retry = 0.012 ครั้ง</p><p>ในขณะที่ ถ้าเราเห็นเป็นค่าความน่าจะเป็นจะทำความเข้าใจ/เห็นภาพได้ง่ายกว่า…</p><p>และผมอยากรู้ว่า จากเลขจำนวนการ retry เรานะหาค่าความน่าจะเป็นที่เทสผ่านได้หรือไม่</p><p><strong>โมเดลของการทำ retry </strong>เรารู้ได้ทันทีว่ารูปแบบความน่าจะเป็นของมันคือ Geometric distribution เพราะ</p><ul><li>ถ้าการทดสอบผ่านตั้งแต่รอบแรก จะไม่มีการ retry</li><li>การ retry ครั้งที่ 1 จะเกิดขึ้นเมื่อการทดสอบรอบแรกไม่ผ่าน</li><li>การ retry ครั้งที่ 2 จะเกิดขึ้นเมื่อการ retry ครั้งที่ 1 ไม่ผ่าน</li><li>การ retry ครั้งที่ 3 จะเกิดขึ้นเมื่อการ retry ครั้งที่ 2 ไม่ผ่าน</li><li>การ retry ครั้งที่ n จะเกิดขึ้นเมื่อการ retry ครั้งที่ n-1 ไม่ผ่าน</li><li>การ retry จะไม่เกิดขึ้นต่อ และพิจารณาเป็น test failed เมื่อการ retry ครั้งที่ n ไม่ผ่าน</li></ul><p>หากต้องการทำความเข้าใจเพิ่มเติม ดูที่นี่</p><p><a href="https://en.wikipedia.org/wiki/Geometric_distribution">Geometric distribution - Wikipedia</a></p><p>ผมได้ทำ simulator ของ model รูปแบบนี้ขึ้นมา กล่าวคร่าวๆ ว่า test มีโอกาสผ่านเป็น p และให้ทำการ retry มากสุดได้ n ครั้ง นั้นหมายความว่า ถ้าให้ n = 3, จำนวนการรันเทสหรือ sample space ใน context นี้ คือ {1,2,3,4}</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b4d9438396be619a1e8e2da34f19e69/href">https://medium.com/media/1b4d9438396be619a1e8e2da34f19e69/href</a></iframe><p>ผมทำการ execute โปรแกรมนี้ โดยกำหนดค่า p = 0.8 จากนั้น จากข้อมูล output ของโปรแกรม เราจะมาดูกันว่า ถ้าผมมี P(x=0), P(x =1), P(x =2), P(x =3) เราจะสามารถหาค่า p (ที่เท่ากับ 0.8 แต่สมมุติว่ายังไม่รู้) ได้หรือไม่</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ea1a515c8fd55e4221ad9858b8c673e/href">https://medium.com/media/6ea1a515c8fd55e4221ad9858b8c673e/href</a></iframe><p>นี้คือ output ของโปรแกรมที่ถูก execute ด้วย paramenter p = 0.8 และรัน 1000 ครั้ง</p><p>จาก output นี้ ผมสามารถบอกได้ว่า</p><p>P(x=1) = 792/1000</p><p>P(x=2) = 158/1000</p><p>P(x=3) = 40/1000</p><p>P(x=4) = 8/1000</p><p>P(x&gt;4) = 2/1000</p><p>จากสมการ Discrete Geometric Distribution</p><p>P(x=n) = p(1-p)^(n-1)</p><p>P(x=1) = (0.792) = p — (1)</p><p>P(x=2) = (0.158) = p(1-p)¹ — (2)</p><p>P(x=3) = (0.040) = p(1-p)² — (3)</p><p>P(x=4) = (0.008) = p(1-p)³ — (4)</p><p>ถามว่าเราจะใช้ค่าจะ p = <strong>0.792</strong> จาก (1) ได้เลยไหม error ก็ยังพอมีอยู่บ้างราวๆ 0.01</p><p>ลองดูที่ (2) ตรงนี้เราจะได้ p = <strong>0.803</strong> ก็ยังมี error อยู่ราวๆ 0.003</p><p>ลองดูที่ (3) แปรงรูปไปมาจะได้สมการดีกรี 3 จะได้ 3 ค่าคือ 0.044, <strong>0.772</strong> และ 1.183 เราสามารถตัด 1.183 ไปได้เลยเพราะไม่ใช่ค่า probability และ 0.044 ซึ่งเมื่อแทนที่สมการ (2) แล้ว<br>0.044(1–0.044)¹ = 0.042 ห่างไกลกับสิ่งที่เราได้ที่ 0.158 (error = 0.116)</p><p>ลองดูที่ (4) p = 0.008 และ <strong>0.783</strong> ผมจะตัด 0.008 ออกไปเพราะ เมื่อแทน p เข้ากับสมการที่ (1) หรือ (2) หรือ (3) ทำให้สมการมีค่า error ที่ยอมรับไม่ได้ เช่นเมื่อแทนที่สมการ (2)<br>0.008(1–0.008)¹ = 0.007 ห่างไกลกับสิ่งที่เราได้ที่ 0.158 (error = 0.151)</p><p>จากสมการ 4 สมการเราได้ค่า ออกมา 4 ค่า คือ {0.792, 0.803, 0.772, 0.783}</p><p>ลองหา RMSE(distance เฉลี่ยของ errors) ดู ออกเป็นราว 0.016</p><p>ผมจะสรุปว่า ค่า p จะอยู่ในช่วง [0.772, 0.803] ซึ่งน่าเชื่อถือพอสมควร ซึ่งค่าจะใกล้สู่ค่าจริงมากกว่านี้ขึ้นอยู่กับจำนวนของ sample ด้วย (ผมลอง 10000 samples ให้ค่า RMSE = 0.004)</p><p><strong>สรุป</strong></p><p>เราไม่อาจหาค่าที่แน่นอนของ p ได้จาก sample แต่เราสามารถตอบได้ว่าค่า p อยู่ในช่วงค่าใดถึงค่าใด และความแม่นยำของ p ขึ้นอยู่กับจำนวนของ sample ด้วย</p><p><strong>Note</strong></p><p>ระหว่างที่เขียน blog นี้ ผมเปิดดูวิดีโอแมวอยู่ contaxt อาจจะข้ามไปมา พูดไม่รู้เรื่อง โปรดติติงและชี้แนะครับ</p><p>References:</p><ul><li><a href="https://en.wikipedia.org/wiki/Root-mean-square_deviation">Root-mean-square deviation - Wikipedia</a></li><li><a href="https://en.wikipedia.org/wiki/Geometric_distribution">Geometric distribution - Wikipedia</a></li></ul><p><a href="https://www.wolframalpha.com/">https://www.wolframalpha.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f7ecf2ffa43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make connection to gcloud sql with jinzhu/gorm in gcloud function]]></title>
            <link>https://medium.com/@tossaponnuanchuay/make-connection-to-gcloud-sql-with-jinzhu-gorm-in-gcloud-function-d5fd986d070?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5fd986d070</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Sun, 26 May 2019 07:53:19 GMT</pubDate>
            <atom:updated>2019-05-26T07:56:11.370Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make a connection to gcloud sql with jinzhu/gorm in gcloud function</h3><p>Assume you already have gcloud functions and gcloud sql, Also you want these two connect together properly. Means without hard-coding/passing instance ip-address. How could we do that ?</p><p>The problem is it requires you to input specific ip-address or length of ip-address with subnet to be set of allowed ip-address that can able to connect to. This is less security and leads to be pwned.</p><p>So, To be able to connect to gcloud sql from gcloud functions, These are follow steps that need to be done.</p><ul><li>Enable Cloud SQL Admin API <a href="https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview">https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview</a></li><li>use database/sql as dialect instead of jinzhu/gorm SQL dialect</li></ul><pre>import (<br>_ &quot;database/sql&quot;<br>_ &quot;github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql&quot;<br>)<br></pre><ul><li>use cloud SQL protocol in connection string</li></ul><pre>user:password@cloudsql(project:zone:instanceId)/database</pre><p>Reference: <a href="https://gist.github.com/erans/795f7616049f310b2a71a50e5df4529a">https://gist.github.com/erans/795f7616049f310b2a71a50e5df4529a</a></p><p>#please let me know if you’ve found any bad gramma, word.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5fd986d070" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using multi-stage build for Golang container image]]></title>
            <link>https://medium.com/@tossaponnuanchuay/using-multi-stage-build-for-golang-container-image-ec30f56053bf?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec30f56053bf</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Sun, 31 Mar 2019 03:37:02 GMT</pubDate>
            <atom:updated>2019-03-31T03:37:02.207Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>M</strong>ulti-stage build can reduce size of container images, especially application that’s made by Go language or programming language that can build to be a binary executable file with low number of dependency, for example: the application requires a configuration file.</p><p>Because it will reduce/cut off number of unnecessary dependency such as library files, compiler etcetera so image size of the application will be very small.</p><p>Let’s compare these 2 docker image files</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b9ff6ae868c7e28860e7de2dd18c88f/href">https://medium.com/media/2b9ff6ae868c7e28860e7de2dd18c88f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7797de7cfc0376f78f81f1a389a9cba0/href">https://medium.com/media/7797de7cfc0376f78f81f1a389a9cba0/href</a></iframe><p>The first Dockerfile build and execute golang application and docker images size is</p><pre>webapp-golang-nobuildstg 781MB</pre><p>As same as the first file, The second Dockerfile will build and execute golang application but, docker image size is</p><pre>webapp-golang-buildstg 11.4MB</pre><p>The difference of these two is the second file is separated into 2 parts, the first part has responsible for getting the executable file and the second part is just copy executable file to another very low profile docker base image(alpine).</p><p>So, in the second docker images, there will not have compiler and library code that was downloaded by go mod download that application surely will not use those things.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec30f56053bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ElasticSearch]]></title>
            <link>https://medium.com/@tossaponnuanchuay/elasticsearch-e6ce0359a924?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6ce0359a924</guid>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 13:26:05 GMT</pubDate>
            <atom:updated>2018-08-17T13:26:05.053Z</atom:updated>
            <content:encoded><![CDATA[<p>เป็น Search Engine ที่ based on Apache lucene. สามารถเป็น NoSQL, Query/Search และมีความสามารถเป็น distributed system. มีดีอีกอย่างคือ สามารถทำ CRUD ผ่าน REST ได้เลย.</p><p><strong>Installation</strong></p><ol><li>Manual</li></ol><p>Download ElasticSearch ได้ที่ <a href="https://www.elastic.co/downloads/elasticsearch">https://www.elastic.co/downloads/elasticsearch</a><br>upzip และมี executable file สามารถ execute ได้เลย ง่ายมากๆ</p><p>2. Docker</p><p><a href="https://hub.docker.com/_/elasticsearch/">https://hub.docker.com/_/elasticsearch/</a></p><p>`docker run -it -p 9200:9200 elasticsearch`<br><a href="https://github.com/docker-library/elasticsearch/blob/be1eb53a6a62a57d0ed17e4287d3fc51a7409a9f/5/Dockerfile">https://github.com/docker-library/elasticsearch/blob/be1eb53a6a62a57d0ed17e4287d3fc51a7409a9f/5/Dockerfile</a></p><p>เช็ค service ว่า up แล้วโดยการ curl <a href="http://localhost:9200/">http://localhost:9200/</a></p><p><strong>Usage</strong></p><p>Structure ของข้อมูลใน elasticsearch มี Index และ Type. 1 Index มีได้หลาย Type และ data point, record จะอยู่ใน Type.</p><ul><li>Create</li></ul><pre>POST <a href="http://localhost:9200/sample_index/simple_type">http://localhost:9200/&lt;INDEX&gt;/&lt;</a>TYPE&gt;<br>{<br>   &quot;text&quot;:&quot;Hello World&quot;<br>}</pre><pre>Response:<br>{<br>    &quot;_index&quot;: &quot;sample_index&quot;,<br>    &quot;_type&quot;: &quot;simple_type&quot;,<br>    &quot;_id&quot;: &quot;AWVIAcBeMxrtSV8zwoqn&quot;,<br>    &quot;_version&quot;: 1,<br>    &quot;result&quot;: &quot;created&quot;,<br>    &quot;_shards&quot;: {<br>        &quot;total&quot;: 2,<br>        &quot;successful&quot;: 1,<br>        &quot;failed&quot;: 0<br>    },<br>    &quot;created&quot;: true<br>}</pre><ul><li>Search/Query ทำได้ 2 แบบ</li></ul><pre>GET <a href="http://localhost:9200/sample_index/simple_type">http://localhost:9200/&lt;INDEX&gt;/&lt;</a>TYPE&gt;/_search?q=&lt;Lucene Query&gt;<br>POST <a href="http://localhost:9200/sample_index/simple_type">http://localhost:9200/&lt;INDEX&gt;/&lt;</a>TYPE&gt;/_search<br>&lt;Search/Aggregate&gt; Json Body</pre><pre>ตัวอย่างเช่น</pre><pre>GET <a href="http://localhost:9200/sample_index/simple_type">http://localhost:9200/&lt;INDEX&gt;/&lt;</a>TYPE&gt;/_search?q=text:Hello*<br>Response:<br>{<br>    &quot;took&quot;: 117,<br>    &quot;timed_out&quot;: false,<br>    &quot;_shards&quot;: {<br>        &quot;total&quot;: 5,<br>        &quot;successful&quot;: 5,<br>        &quot;skipped&quot;: 0,<br>        &quot;failed&quot;: 0<br>    },<br>    &quot;hits&quot;: {<br>        &quot;total&quot;: 1,<br>        &quot;max_score&quot;: 1,<br>        &quot;hits&quot;: [<br>            {<br>                &quot;_index&quot;: &quot;sample_index&quot;,<br>                &quot;_type&quot;: &quot;simple_type&quot;,<br>                &quot;_id&quot;: &quot;AWVIAcBeMxrtSV8zwoqn&quot;,<br>                &quot;_score&quot;: 1,<br>                &quot;_source&quot;: {<br>                    &quot;text&quot;: &quot;Hello World&quot;<br>                }<br>            }<br>        ]<br>    }<br>}</pre><ul><li>Update</li></ul><pre>PUT <a href="http://localhost:9200/sample_index/simple_type">http://localhost:9200/&lt;INDEX&gt;/&lt;</a>TYPE&gt;/&lt;ID&gt;</pre><pre>ตัวอย่าง<br>  <a href="http://localhost:9200/sample_index/simple_type/AWVIAcBeMxrtSV8zwoqn">http://localhost:9200/sample_index/simple_type/AWVIAcBeMxrtSV8zwoqn</a><br>{<br> &quot;text&quot;: &quot;This is first time. I update datapoint in elasticsearch&quot;<br>}</pre><pre>Response:<br>{<br>    &quot;_index&quot;: &quot;sample_index&quot;,<br>    &quot;_type&quot;: &quot;simple_type&quot;,<br>    &quot;_id&quot;: &quot;AWVIAcBeMxrtSV8zwoqn&quot;,<br>    &quot;_version&quot;: 2,<br>    &quot;result&quot;: &quot;updated&quot;,<br>    &quot;_shards&quot;: {<br>        &quot;total&quot;: 2,<br>        &quot;successful&quot;: 1,<br>        &quot;failed&quot;: 0<br>    },<br>    &quot;created&quot;: false<br>}</pre><ul><li>Delete</li></ul><pre>DELETE <a href="http://localhost:9200/sample_index/simple_type">http://localhost:9200/&lt;INDEX&gt;/&lt;</a>TYPE&gt;/&lt;ID&gt;</pre><pre>ตัวอย่าง<br>  <a href="http://localhost:9200/sample_index/simple_type/AWVIAcBeMxrtSV8zwoqn">http://localhost:9200/sample_index/simple_type/AWVIAcBeMxrtSV8zwoqn</a></pre><pre>Response:<br>{<br>    &quot;found&quot;: true,<br>    &quot;_index&quot;: &quot;sample_index&quot;,<br>    &quot;_type&quot;: &quot;simple_type&quot;,<br>    &quot;_id&quot;: &quot;AWVIAcBeMxrtSV8zwoqn&quot;,<br>    &quot;_version&quot;: 3,<br>    &quot;result&quot;: &quot;deleted&quot;,<br>    &quot;_shards&quot;: {<br>        &quot;total&quot;: 2,<br>        &quot;successful&quot;: 1,<br>        &quot;failed&quot;: 0<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6ce0359a924" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Contribute At ws]]></title>
            <link>https://medium.com/ntossapo/contribute-at-ws-ec483a0e7ccb?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec483a0e7ccb</guid>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Tue, 06 Feb 2018 15:19:40 GMT</pubDate>
            <atom:updated>2018-02-06T15:19:40.079Z</atom:updated>
            <content:encoded><![CDATA[<p>ws เป็น nodejs lib ที่ใช้งานอย่างแพร่หลาย น่าจะย่อมาจาก websocket น่าจะเป็น lib แรกๆ เลยที่เล่นเรื่อง websocket protocol ว่าง ๆ <a href="https://tools.ietf.org/html/rfc6455">ลองเอา RFC ไปเคี้ยวเล่น</a></p><p>กำลังทำ websocket proxy เพื่อให้ puppeteer scale ได้และสามารถใช้ remote browser ได้ (เท่าที่อ่านเจอ chromium ไม่ได้ bind address เป็น global เพราะฉนั้นก็จะ connect TCP session จาก host อื่นไม่ได้) โดย puppeteer เนี่ย มันใช้ ws ในการสื่อสารกับ browser</p><p>ปัญหาที่ต้อง contribute คือ design ไว้ว่าจะเปิด local chromium ให้และเปิด ws proxy ไว้ที่ port 0 (port 0 หมายถึง port ใดๆ ที่ว่าง ณ ขณะนั้น) ผู้ที่ต้องการใช้ chromium ก็ต่อ ws ไปที่ url ที่จัดหาให้ แต่!! เมื่อเราเปิด port 0 เราไม่สามารถรู้ได้เลยว่า แล้ว os มันจัดหา port อะไรให้เรา หมายความว่า เปิด port 0 แต่ไม่รู้ว่า port ที่เปิดจริงๆ คือ port อะไร</p><p>จริงจะใช้ _server ก็ได้ แต่ถ้าจะเอาจริงๆ ก็ค่อนข้างเหี้*ไปหน่อย ทำให้ถูกหลักอนามัยหน่อยละกัน</p><p>เริ่ม contribute คือเข้าไปอ่าน code ของ ws เขียนไว้สวยมาก ประณีต เลยลอง fork และเขียน ให้สามารถ return _server ออกมาผ่าน public function แล้วเปิด Pull Request ไป Upstream เลย โยนหินถามทางดู</p><p>ไม่ผ่านดิ มันมี CI !!! Tool เขาเทพมาก มี code coverage, AppVeyor กับ Travis แบบนี้ก็ต้องเขียน Test หละ</p><p>ภายใน ws มีการ setup development tool ไว้เรียบร้อยแล้ว npm test ได้เลย สิ่งแรกที่เจอคือ eslint ซึ่งโหดสัสๆ มีตัวอย่างดังนี้</p><ul><li>function address(){... แบบนี้ไม่ได้ ต้อง function address () {...</li><li>if ถ้าไม่มี {} ให้อยู่บรรทัดเดียว เป็นดังนี้ if(a) throw new Error();</li><li>throw เป็น object เท่านั้น</li></ul><p>เขียนไปสักพักก็ผ่าน ไม่ได้ยากมากมาย เขียน test เรียนร้อย ระหว่างนั้น เจ้าของก็เข้ามา review พอดี ปรับเปลี่ยนนิดหน่อย และส่งอีกรอบ</p><p>โดนตีกลับไปมา 2-3 รอบ เพราะต้องเขียน comment function ให้ถูก format และเขียน doc ให้เขาด้วย (หลัง ๆ ดึกเกินตามแก้ไม่ไหว พี่เจ้าของแกแก้เองแม่งเลย)</p><p>สุดท้ายก็ได้ merge!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*gtvWz2stjnUyC3PjLMuPAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*G2ggNockeIWNMnLDZGuOwg.png" /></figure><p>เรื่องนี้สอนให้รู้ว่า การเปิด PR ที่ไหนๆ ไม่ได้ยากอย่างที่คิด</p><p>Thank <a href="https://medium.com/u/a7cafba2c74c">Luigi Pinca</a> For nice merge experience. You’re awesome!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec483a0e7ccb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ntossapo/contribute-at-ws-ec483a0e7ccb">Contribute At ws</a> was originally published in <a href="https://medium.com/ntossapo">ntossapo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Load Balance ครับ !! by NGINX]]></title>
            <link>https://medium.com/@tossaponnuanchuay/load-balance-%E0%B8%84%E0%B8%A3%E0%B8%B1%E0%B8%9A-by-nginx-7cb567c62ba5?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cb567c62ba5</guid>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Tue, 28 Nov 2017 14:30:53 GMT</pubDate>
            <atom:updated>2017-11-28T14:30:53.610Z</atom:updated>
            <content:encoded><![CDATA[<p>ทำ load balance ด้วย nginx</p><ol><li>สร้าง replication ของ service ขึ้นมา n machine</li><li>สร้าง/หา node ที่เอาไว้เป็น load balancer</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*yE-M2KUfo9-vuYjI8VIPXQ.png" /></figure><p>จากรูป มี Spring REST API อยู่ 4 ตัว ชื่อ instance-01 … instance-04</p><p>lbalance คือ load balancer ที่จะเอาไว้ใช้กระจาย load</p><p>ที่ load balancer ติดตั้ง nginx และจัดการ config ดังนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5320779b899e82e28cf9f624fbc942fd/href">https://medium.com/media/5320779b899e82e28cf9f624fbc942fd/href</a></iframe><p>127.xxx.xxx.xxx คือ ip ของ instance ต่างๆ</p><p>reload nginx ก็เสร็จเลยครับ</p><p>more detail <a href="https://www.nginx.com/resources/admin-guide/load-balancer/">https://www.nginx.com/resources/admin-guide/load-balancer/</a></p><p>ปล ถ้าใช้ session จัดการกันดีๆ นะครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cb567c62ba5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How good are those measurement tools (HTTP Load Testing)]]></title>
            <link>https://medium.com/@tossaponnuanchuay/how-good-are-those-measurement-tools-http-load-testing-20129fff1301?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/20129fff1301</guid>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Sun, 12 Nov 2017 12:04:52 GMT</pubDate>
            <atom:updated>2017-11-12T13:32:25.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHK853Qrrg5gXrQ0e4wEGQ.jpeg" /></figure><blockquote>จะวัดขนาดสิ่งของสักอย่างหนึ่ง ไม้บรรทัดคุณดีแค่ไหน</blockquote><p>จากกระทู้ถาม วันที่ 6 พฤษจิกายน 2560 ณ Page Facebook แห่งหนึ่ง ก่อให้เกิด Yoda jargon ด้านบน ที่ทำให้ต้องพิจารณา</p><p>กระทู้เปรียบเทียบความเร็วของภาษาหนึ่งกับภาษาหนึ่ง ในการใช้งานรูปแบบหนึ่ง นำเสนอด้วยค่าตัวเลขต่างๆ ทำให้เห็นความแตกต่างของภาษาแต่ละภาษาและนำไปสู่การเปรียบเทียบ</p><p>การจะได้ความแตกต่างนั้นมา จะต้องใช้เครื่องมือวัดที่มีความน่าเชื่อถือและเป็นที่ยอมรับ วัดตัวแปรหนึ่งกับสิ่งของสองสิ่ง และนำค่าสองค่ามาเปรียบเทียบกัน</p><p>ประเด็นคือ จะรู้ได้อย่างไรว่าเครื่องมือวัดที่กำลังใช้งานกันอยู่ เป็นเครื่องมือที่มีความน่าเชื่อถือและเป็นที่ยอมรับ</p><h3>Experiment</h3><p>การทดลองชุดนี้จะแสดงผลลัพธ์ที่ได้จากเครื่องมือวัดประสิทธิภาพ HTTP หลากหลายยี่ห้อดังนี้</p><ul><li>wg/wrk</li><li>apache ab</li><li>loadtest.js</li><li>artillery</li><li>adjust/go-wrk</li><li>rakyll/hey</li></ul><p>จะทำงานอยู่บน 5$ digitalocean SG ที่วัดกับ environment หนึ่งๆ ที่ทำงานอยู่บน 5$ digitalocean SG เช่นกัน และเชื่อมต่อกับแบบ private network</p><p>Environment ออกแบบโดยให้ response request หลังจากรอ 100ms ไม่จำกัดจำนวน connection เป็นดังเช่น code นี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e359175dec0c381ddd05db01b1a62b62/href">https://medium.com/media/e359175dec0c381ddd05db01b1a62b62/href</a></iframe><blockquote><strong>ดังนั้น ในอุดมคติแล้ว 1 วินาที ควรจะได้ใกล้เคียง <br>10 responses/second/connection<br>แต่ต้องไม่เท่ากับ 10 เพราะข้อมูลต้องใช้เวลาในการเดินทางและการต่อคิว</strong></blockquote><p>การทดลองแบ่งออกเป็น 2 ชุด</p><ul><li>1 connection</li><li>1000 connection</li></ul><p>แต่ละชุดทดลอง ใช้เวลา 1, 30, 60, 120, 150, 180 วินาที</p><h3>Result</h3><h4><strong><em>1 connection —</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RnEwRc_QWpIFHT21VMqTIQ.png" /></figure><p>จะเห็นว่าผลการทดลองในแต่ละเครื่องมือ ค่อนข้างเป็นไปตามที่คาดไว้คือ ใกล้เคียง 10 แต่ไม่เท่ากับ 10</p><ul><li>loadtest.js ปัดค่าเป็นจำนวนเต็ม</li><li>ในระยะเวลาการทดสอบที่ 1s ผลการทดลองให้ผลไม่ตรงกับที่คาดไว้ อาจจะเพราะว่าจำนวน request น้อยเกินไป</li><li>wg/wrk ให้ผลลัพธ์ใกล้เคียงกับที่ต้องการมากที่สุด ถ้าหากไม่นับการทดสอบที่ 1s</li><li>rakyll/hey และ ab ให้ผลการทดสอบดีสุดในทุกช่วงเวลาการทดสอบ</li></ul><h4><strong><em>1000 connections —</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ItXwed8rM7n17sMbP5aNQA.png" /></figure><p>ค่าที่คาดหวังไว้คือ ใกล้เคียงกับ 10000 request/sec แต่ผลลัพธ์ที่ได้ส่วนใหญ่ให้ค่าต่ำความที่คิดไว้มาก อาจเพราะจำนวน connection มากเกินไปจนทำให้ queue packet ล้น</p><ul><li>wg/wrk ให้ผลลัพธ์ใกล้เคียงที่สุด</li><li>ไม่สามารถทดสอบด้วย artillery ได้ จำนวน connection อาจมากเกินไป</li><li>loadtest.js ให้ผลลัพธ์แย่สุด</li></ul><h3>Conclusion</h3><p>การทดลองนี้แสดงให้เห็นศักยภาพของ wrk ที่ทำงานได้ดีที่สุด รองลงมาคือ hey ที่ว่ากันว่าเป็น modern ab ที่เขียนด้วย go</p><p>Tools ที่เขียนด้วย js นั้นให้ผลที่ไม่ค่อยดี อาจเนื่องจากการทำ multi-thread, multi-processes นั้นทำได้ยาก ด้วยภาษาของมันเอง</p><h3>ป.ล.</h3><ul><li>เหตุผลที่ไม่ได้ทดสอบ jmeter, tsung นั้นเพราะว่า ใช้ linux console และถ้าศึกษาเพิ่มเติมจะใช้เวลาเยอะเกินไป</li></ul><h3><strong>Appendix</strong></h3><ul><li>1 connections</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*XAlxMwNKJpTBQg46IxcWuw.png" /></figure><ul><li>1000 connections</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*sfeYsC036aHwR2x6vRW6_g.png" /></figure><ul><li>5$ digitalocean = 1 core/512 MB of RAM/20GB-SSD with Ubuntu 16.04.3 x64</li><li>go 1.9.2</li><li>node v8.9.0</li><li>fs.file-max = 1000000 on load generator machine</li><li>ulimi= 655350 on load generator machine</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20129fff1301" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[แก้ปัญหา callback hell ด้วย Promise ฉบับ newbie]]></title>
            <link>https://medium.com/@tossaponnuanchuay/%E0%B9%81%E0%B8%81%E0%B9%89%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2-callback-hell-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-promise-%E0%B8%89%E0%B8%9A%E0%B8%B1%E0%B8%9A-newbie-c3988394937a?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3988394937a</guid>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Thu, 15 Jun 2017 13:54:57 GMT</pubDate>
            <atom:updated>2017-06-15T13:54:57.951Z</atom:updated>
            <content:encoded><![CDATA[<p>เป็นมือใหม่หัดเขียน JS เขียนมาได้สักระยะหนึ่งก็พบว่า code ของตัวเองนั้นอ่านยาก ทำความเข้าใจใหม่ยาก โค๊ดมีกลิ่นตุๆ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01032143e95b405fd985983d361997c4/href">https://medium.com/media/01032143e95b405fd985983d361997c4/href</a></iframe><p>จากโค๊ดด้านบน ถ้าผมในอีก 4–5 เดือนข้างหน้ามาอ่าน จะบอกว่า</p><blockquote>“ไอฟัก เขียนอะไรไวเนี่ย”</blockquote><p>ลด ละ เลิกวิธีการเขียนแบบนี้ แล้วสนใจสิ่งใหม่ๆ สักนิด จะได้ไม่เสียใจภายหลัง</p><p>ใน JS มี Promise จะช่วยแก้ปัญหาเหล่านี้ให้เรา โดย หลัก Promise จะมีส่วนประกอบที่หน้าจดจำอยู่ 5สิ่งคือ</p><ul><li>function ที่จะให้ promise ทำงาน</li><li>resolve คือฟังชั่น เรียกเมื่อสิ่งที่เราอยากให้ทำ ทำงานได้ถูกต้อง</li><li>reject คือฟังก์ชัน เรียกเมื่อสิ่งที่เราอยากให้ทำ ทำงานผิดแปลกไปจากที่ต้องการ</li><li>then หลังจากนั้น จะทำอะไรต่อ</li><li>catch ถ้ามันทำงานผิดแปลก จะทำอะไรต่อ</li></ul><p>ลองง่ายๆ โดยการเอา code ข้างบน มาแปลกเป็น promise (ขอแค่ 2 api พอนะ)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a021a9500e859f28e7ad4b746cd63ca7/href">https://medium.com/media/a021a9500e859f28e7ad4b746cd63ca7/href</a></iframe><p>ใน call api1 ถ้าฟังก์ชันทำงานจนเจอ resolve มันก็ไปทำใน .then อันถัดไป</p><p>ถ้าไม่เจอ resolve ไปเจอ reject ก็จะข้ามไปทำงานใน catch</p><p>กรณีที่ ใน then เรายังมีสิ่งที่ต้องทำต่อ เราสามารถ return promise กลับไปได้</p><p>ถ้า resolve ก็จะทำใน then ถัดไป, ถ้า reject ก็จะทำใน catch</p><p>อีกประเด็นที่สำคัญคือถ้าฟังก์ชัน/Lib นั้น return Promise มาให้อยู่แล้วเราสามารถ .then ต่อๆ กันไปได้เลยนะ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c48a961ba1e53558856ab32552794384/href">https://medium.com/media/c48a961ba1e53558856ab32552794384/href</a></iframe><p>สุดท้าย สำคัญเลยคือ ลด ละ เลิกการเขียนโค๊ดแย่ๆ เขียนโค้ดให้คนใช้โค้ดคนถัดไปด่า เขียนโค๊ดกลิ่นตุๆ ให้เวลาและใส่ใจกับสิ่งที่จะแก้ปัญหามัน</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3988394937a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ทำอะไรบ้างกับ Dashboard ที่เอาไว้โชว์ในงาน CoE-ICT PSU Phuket Senior Project Showcase]]></title>
            <link>https://medium.com/ntossapo/%E0%B8%97%E0%B8%B3%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B8%9A%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%81%E0%B8%B1%E0%B8%9A-dashboard-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%80%E0%B8%AD%E0%B8%B2%E0%B9%84%E0%B8%A7%E0%B9%89%E0%B9%82%E0%B8%8A%E0%B8%A7%E0%B9%8C%E0%B9%83%E0%B8%99%E0%B8%87%E0%B8%B2%E0%B8%99-coe-ict-psu-phuket-senior-project-showcase-37f7d6d66027?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/37f7d6d66027</guid>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Sat, 13 May 2017 14:51:18 GMT</pubDate>
            <atom:updated>2017-05-13T14:51:18.370Z</atom:updated>
            <content:encoded><![CDATA[<p>ราว ๆ เดือนเมษา ปี 2017 ผมได้อาสาที่จะทำ dashboard ที่จะใช้โชว์ในงาน Senior Project Showcase เป็น Dashboard ที่นำยอดไลค์ แอคชั่นต่างๆ และ แชร์จากแฟนเพจมาคิดเป็นคะแนนและแสดงบนบอร์ดในวันงาน สิ่งที่คาดหวังจากการทำงานนี้เพียงเพื่ออยากได้ประสบการณ์ใหม่ ๆ และความรู้ใหม่ ๆ</p><p>ผมจะต้องทำงานร่วมกับ อ. อีกท่านหนึ่งซึ่งประสงค์จะเรียนรู้ AngularJS4 ซึ่ง อ. ท่านจะทำส่วนของที่ใช้แสดงบน Dashboard และ UI ส่วนผมมีหน้าที่ทำ ส่วนของการเก็บข้อมูล, API และ อื่นๆ ตามที่อยากทำ</p><h3><strong>Facebook API &amp; Data Polling</strong></h3><p>สิ่งแรกที่ทำคือทดลองกับ Facebook ว่าเราสามารถดึงยอด ไลค์, แอคชัน และ แชร์มาจากแฟนเพจได้หรือไม่ และวิธีการใด</p><p>วิธีการนั้นไม่ยากมาก เราสามารถลอง Query ข้อมูลจาก Facebook ได้ผ่าน Tool ตัวนี้<br><a href="https://developers.facebook.com/tools/explorer/">Facebook Explorer</a></p><p>เราพยายาม Query ครั้งเดียวให้ได้ข้อมูลที่ต้องการแต่พบปัญหาเรื่อง Pagination ทำให้เราต้อง Query หลายๆ รอบและลำบากมากเพราะรู้สึกว่ามันไม่น่าใช้งาน</p><p>เราจึงแบ่งการ Query ออกเป็น 2 ส่วน</p><ul><li>ดึง ID ข้องทุก Post บน Fanpage</li><li>ดูว่าแต่ละ ID มี Likes, Actions, Shares เท่าไหร</li></ul><p>ซึ่งทำงานได้ค่อนข้างดีเมื่อเริ่มโปรเจค(หลังๆชักจะไม่ดี)</p><p>สร้างโปรเจค NodeJS ขึ้นมาและเขียน Code เพื่อ Query เหมือนตอนที่ได้ทดลองและออกแบบโดยสามารถใช้ Library</p><ul><li><a href="https://www.npmjs.com/package/fbgraph">fbgraph</a></li></ul><p>และนำไปเก็บไว้ที่ MongoDB เพราะเราไม่อยากออกแบบแยกเป็น Tables และ Query โดยการใช้ Join ไปเรื่อยๆ มันค่อนข้างซับซ้อน เราอยากทำอะไรที่มันง่ายๆ และทำได้อย่างที่เราอยากได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*QeEy7g8du4favikBl9Lxdg.png" /></figure><h3><strong>Measurement using Grafana &amp; Prometheus</strong></h3><p>จากนั้นเราก็เข้ามาทำตัว measurement ด้วยความอยากรู้ว่า ข้อมูลที่เราเก็บและการเคลื่อนไหวของ Nodejs มันเป็นไปอย่างไรบ้าง</p><p>เลือกใช้ Prometheus และ Grafana เพราะมันง่ายมากๆ(ถ้าใช้กับ Docker นะ)</p><p><a href="https://medium.com/@tossaponnuanchuay/%E0%B9%83%E0%B8%8A%E0%B9%89-prometheus-grafana-%E0%B8%97%E0%B8%B3-monitoring-%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%87%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2-ba0ca511236b">วิธีการใช้งานได้เคยเขียนไปใน Blog แล้วตามนี้เลย</a></p><p>โดยเรามี Graph ที่แสดงความเป็นไปของ Like, Share, Actions, และ Traffic ของ API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbqbcGhRtiqqRNgF4iLmEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tldKI4d-Q2_BreCkFlwrig.jpeg" /></figure><h3><strong>Automation Deployment</strong></h3><p>เราใช้ Jenkins ในการช่วย Deploy ด้วย (โปรเจคไม่มี Test Sad…) โดยติดตั้ง Jenkins ไว้ใน Production และทำ Webhook เมื่อมี dev push code ขึ้นไปบน Github</p><p>Script สำหรับ Deploy NodeJS โดยใช้ pm2ก็จะราวๆนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cede379cf073f1ed457eb152b43e9135/href">https://medium.com/media/cede379cf073f1ed457eb152b43e9135/href</a></iframe><p>ถ้าหากอยากดูของที่ pm2 ทำงานอยู่ จะต้อง su jenkins ก่อน แล้วค่อยใช้ pm2 นะ เพราะ jenkins สั่ง pm2 ทำงานใน user jenkins เอง</p><p>Jenkins เปิดให้ อ. ที่ทำ Frontend ได้ใช้งานด้วย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Q3-NaFjGSRxzU4bVpxRRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-53_4kKYfleQkrSnDhdAXg.png" /></figure><p>Feedback จากการใช้ Jenkins</p><ul><li>Dev ที่มีอยู่ 3 คนนั้นรู้สึกมหัศจรรย์มากเพราะมันแจ่มมากๆ</li></ul><blockquote><strong>คุณ push code ของคุณและมันจะอยู่บน production ภายใน 20 วินาที</strong></blockquote><ul><li>เราควรเขียน Test เพื่อ Cover ความผิดพลาด ทั้ง Unit และ Integration</li></ul><h3><strong>Register</strong></h3><p>อ. บ่นๆว่า Fanpage ที่เรากำลังทำนั้นให้เด็กโพสงานของตัวเองลงไปไม่ได้และถ้าโพสลงไปมันจะไปอยู่ใน Visitor Posts แทน ทำให้ Data polling ของเรา post ไม่เจอ</p><p>จะทำเองด้วยมือ ก็คงลำบากเพราะว่ามันมีหลายโปรเจค โพสกันมือหงิกแน่นอน</p><p>สิ่งที่ต้องทำคือหน้าเว็บ Register ที่จะต้องนำข้อมูลไปโพสบน Fanpage โดย Admin เป็นคนโพส</p><p>ปัญหาคือจะให้ Admin โพสอัตโนมัติได้ยังไง?</p><p>เราใช้ IFTTT ช่วยในการโพส โดยทำหน้าเว็บ Register ง่ายๆ ขึ้นมา และส่งให้ IFTTT ช่วยโพสให้ ง่ายมากๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*CumpmILsPy47skWAOz4-dA.png" /></figure><h3>สรุปสิ่งที่ได้ใช้และเรียนรู้ในงานนี้</h3><ul><li>เราใช้ docker ทุกอย่างเท่าที่ทำได้ เราข้ามขั้นตอนการติดตั้ง และการ configuration เราควบคุมมันได้ และมันดีมากๆ</li><li>เรามี Measurement เราเห็นความเป็นไปของข้อมูลที่เข้ามา เราตรวจเจอสิ่งผิดปกติได้ทันทีและรู้ได้ทันทีว่าเกิดอะไรขึ้น</li><li>เราใช้ Automation Tool มันทำให้เราไม่หัวร้อน มันรวดเร็วและทำให้เราสบายขึ้น</li></ul><h3>ปัญหา</h3><p>เรา Design Data Polling ผิดแบบ ทำให้เกิดเหตุการณ์แบบนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4ACgWypn5prRWR-MbslGQ.png" /></figure><p>มันเกิดจากการที่เราขอข้อมูลจาก Facebook มากเกินไป เพราะว่าเราเรียกดูข้อมูลในระดับ PostID ในเพจมี PostID จำนวนมาก ราวๆ 80 Post และแต่ละ Post เราขอข้อมูลทุกๆ 10 วินาที</p><h3><strong>มันควรจะ</strong></h3><ul><li>มี Test :(</li><li>เป็นงานที่ นศ ช่วยกันทำ มันจะดีมากเพราะว่าเราได้เรียนรู้สิ่งที่ใช้ได้เร็วมากๆ</li><li>เราควรออกแบบ Data Polling ให้ดีกว่านี้</li></ul><h3><strong>Github</strong></h3><ul><li><a href="https://github.com/tspn/psu-project-fb">https://github.com/tspn/psu-project-fb</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37f7d6d66027" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ntossapo/%E0%B8%97%E0%B8%B3%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B8%9A%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%81%E0%B8%B1%E0%B8%9A-dashboard-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%80%E0%B8%AD%E0%B8%B2%E0%B9%84%E0%B8%A7%E0%B9%89%E0%B9%82%E0%B8%8A%E0%B8%A7%E0%B9%8C%E0%B9%83%E0%B8%99%E0%B8%87%E0%B8%B2%E0%B8%99-coe-ict-psu-phuket-senior-project-showcase-37f7d6d66027">ทำอะไรบ้างกับ Dashboard ที่เอาไว้โชว์ในงาน CoE-ICT PSU Phuket Senior Project Showcase</a> was originally published in <a href="https://medium.com/ntossapo">ntossapo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ใช้ Prometheus, Grafana ทำ Monitoring อย่างง่าย]]></title>
            <link>https://medium.com/ntossapo/%E0%B9%83%E0%B8%8A%E0%B9%89-prometheus-grafana-%E0%B8%97%E0%B8%B3-monitoring-%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%87%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2-ba0ca511236b?source=rss-9cc26d61f9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba0ca511236b</guid>
            <dc:creator><![CDATA[Tossapon Nuanchuay]]></dc:creator>
            <pubDate>Mon, 01 May 2017 06:28:12 GMT</pubDate>
            <atom:updated>2017-05-01T15:09:37.417Z</atom:updated>
            <content:encoded><![CDATA[<p>วันนี้จะนำเสนอวิธีการใช้ prometheus และ grafana ในการทำระบบ monitoring อย่างง่าย</p><p>โดย prometheus และ grafana จะใช้ docker image ที่มีอยู่แล้วเพื่อให้ง่ายและไม่หัวร้อนตอนติดตั้ง</p><p>ขั้นตอนแรกคือสร้าง prometheus container ขึ้นมา โดยจะใช้ image ของ prom/prometheus</p><pre>docker run — name prometheus -d -p 9090:9090 -v /root/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus</pre><p>เรา mount volumn ของไฟล์ prometheus.yml ได้ เขียนไว้ดังนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71e2c087b857d63c6059e5377666ff5f/href">https://medium.com/media/71e2c087b857d63c6059e5377666ff5f/href</a></iframe><p>ตาม config นี้ prometheus จะดึงข้อมูลที่ localhost:9095 ที่ endpoint /metrics ทุกๆ 5 วินาที</p><p>อีกอย่างที่สำคัญคือ เราควรจะ mount volumn ที่เก็บข้อมูลออกมาด้วยนะ ไม่ควรจะให้ข้อมูลอยู่ใน container</p><p>เราได้ prometheus แล้ว</p><p>ต่อไปคือ grafana ก็ใช้ docker image ที่มีอยู่แล้วเหมือนกัน</p><p>จะใช้ image grafana/grafana ซึ่งใช้งานดังนี้</p><pre>docker run -i -p 3000:3000 \<br>  -e &quot;GF_SERVER_ROOT_URL=http://coepkt.org&quot;  \<br>  -e &quot;GF_SECURITY_ADMIN_PASSWORD=password  \<br>  grafana/grafana</pre><p>เข้าใช้งานผ่าน port 3000 username: admin และ password ตามที่ได้กำหนดไว้ตอนสร้าง container</p><p>เข้าไป setup datasource ใน grafana โดยเพิ่ม datasource prometheus ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*aecxpSK44Lh7ijMGIiur8Q.png" /></figure><p>จากนั้นลองสร้างแอปพลิเคชันง่ายๆ โดยใช้ nodejs เพื่อให้ prometheus มาดึงข้อมูลไปเก็บ</p><p>การใช้งาน nodejs กับ prometheus เราสามารถใช้งาน prometheus-client ได้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9e6c07bd993170df261d3aad11b124c/href">https://medium.com/media/c9e6c07bd993170df261d3aad11b124c/href</a></iframe><p>จากไฟล์ m.js คือการดึงข้อมูลจาก mongodb และ เซ็ตค่า numberOfShare เมื่อเรารันแอพนี้ และเข้าไปที่ host:9095/metrics จะได้เห็น</p><pre># HELP psu_project_post_count number of post count in facebook<br># TYPE psu_project_post_count counter<br>psu_project_post_count{} 92<br># HELP psu_project_post_fetcher_count number of post fetcher<br># TYPE psu_project_post_fetcher_count counter<br>psu_project_post_fetcher_count{} 84<br># HELP psu_project_api_request_per_sec api request/sec<br># TYPE psu_project_api_request_per_sec counter<br>psu_project_api_request_per_sec{} 2<br># HELP psu_project_like_count number of like<br># TYPE psu_project_like_count gauge<br>psu_project_like_count{period=&quot;10sec&quot;} 2063<br># HELP psu_project_love_count number of love<br># TYPE psu_project_love_count gauge<br>psu_project_love_count{period=&quot;10sec&quot;} 97<br># HELP psu_project_wow_count number of wow<br># TYPE psu_project_wow_count gauge<br>psu_project_wow_count{period=&quot;10sec&quot;} 55<br># HELP psu_project_haha_count number of haha<br># TYPE psu_project_haha_count gauge<br>psu_project_haha_count{period=&quot;10sec&quot;} 1<br># HELP psu_project_share_count number of share<br># TYPE psu_project_share_count gauge<br>psu_project_share_count{period=&quot;10sec&quot;} 2145</pre><p>prometheus ก็จะมาดึงข้อมูลจากที่นี้ไปเก็บไว้ ตามที่เขียนไว้ใน prometheus.yml</p><p>จากนั้นเข้าไปสร้างกราฟที่ grafana ทดลอง query หลายแบบ ตามที่ prometheus ทำได้ ก็จะได้กราฟออกมาดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*39lnPLs2XhKcbmM7Smk54A.png" /></figure><p>Github: <a href="https://github.com/tspn/psu-project-fb/">https://github.com/tspn/psu-project-fb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba0ca511236b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ntossapo/%E0%B9%83%E0%B8%8A%E0%B9%89-prometheus-grafana-%E0%B8%97%E0%B8%B3-monitoring-%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%87%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2-ba0ca511236b">ใช้ Prometheus, Grafana ทำ Monitoring อย่างง่าย</a> was originally published in <a href="https://medium.com/ntossapo">ntossapo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>