Funliday 最近做了大改版,其中一項功能就是把去年中因為 Google 要開始收費而暫時拿掉的「推薦景點」加回來,這個功能就是提供使用者指定區域附近評價較高的景點。
大家現在在使用景點瀏覽時,應該有時候會發現資料出來的速度不一致,慢的時候 (超過 5 秒,有時候會落在 10 秒以上) 代表可能有其他使用者正在查詢這個區域的「推薦景點」,思考邏輯就是在同一區域只要有一個使用者查詢過這個區域的「推薦景點」,其他同區域的使用者就會因為已經查詢過這份資料 (如熱門景點:台北 101、東京晴空塔...等) 而受惠。
在目前小編能力還無法將查詢效能大幅改善的狀況之下 Orz,若同一個區域有多個使用者同時查詢,每個查詢都要花費 10 秒的話,這樣子資料庫會浪費超多時間在不必要的查詢上面。
像這類無法避免的使用者行為,但又要減少資料庫無謂的同樣操作時,小編突然想到之前 Triton Ho 在上課時提到的 exclusive lock。
Advisory lock 是 PostgreSQL 的一種 lock 機制,可以在 application 層操作 exclusive lock (以下稱為 X lock) 或是 shared lock (以下稱為 S lock)。當使用 X lock 時,若非同一個 session 是無法將它 unlock,而 S lock 則是任何一個 session 都可以用 S lock 拿取 (acquire) 相同的 lock,但不可以用 X lock 拿取 S lock。
依小編的這個使用情境,可以在查詢「推薦景點」之前先問一次 Redis 有沒有這個區域的資料,有的話直接從 Redis 取得,沒有的話就先到 PostgreSQL acquire 一次 X lock,如果可以成功的話,則表示還沒有其他 session 正在查詢這個區域的資料,所以可以在 acquire 之後直接查詢,接著再 unlock 這個 X lock;但如果無法 acquire 的話,則表示目前有其他 session 正在查,所以直接回 client 查詢中的訊息,可以等一下再查。
所以小編使用 PostgreSQL 的 advisory lock 及 Redis 就可以達成不會有同一時間查詢相同耗時的查詢了。
其實再好一點的作法可能是把這類耗時的查詢丟到 MQ 裡面,讓 response 先回 client,等到 MQ 做完這個 job 之後,再用 push notification 通知 client 到 Redis 取得已經計算完的資料。或是用 polling 固定 n 秒鐘查詢一次,這都要視你的基礎設施而定。小編現在是先用 polling 的方式簡單處理,雖然方法有點笨,但在沒多餘心力 (Elasticsearch 太博大精深了 Orz) 的狀態之下就先這樣做了。
#funliday #postgresql #lock #advisorylock
同時也有10000部Youtube影片,追蹤數超過2,910的網紅コバにゃんチャンネル,也在其Youtube影片中提到,...
「elasticsearch client」的推薦目錄:
- 關於elasticsearch client 在 Kewang 的資訊進化論 Facebook 的最佳解答
- 關於elasticsearch client 在 夏榮慶 一百種生活 Facebook 的最讚貼文
- 關於elasticsearch client 在 コバにゃんチャンネル Youtube 的最佳解答
- 關於elasticsearch client 在 大象中醫 Youtube 的最讚貼文
- 關於elasticsearch client 在 大象中醫 Youtube 的最佳貼文
- 關於elasticsearch client 在 Official Elasticsearch client library for Node.js - GitHub 的評價
- 關於elasticsearch client 在 The client noticed that the server is not a supported ... 的評價
- 關於elasticsearch client 在 Micronaut Elasticsearch 的評價
- 關於elasticsearch client 在 Introduction into the Elasticsearch Python Client - YouTube 的評價
- 關於elasticsearch client 在 Introduction into the JavaScript Elasticsearch Client - YouTube 的評價
elasticsearch client 在 夏榮慶 一百種生活 Facebook 的最讚貼文
| 徵才快訊 |
有興趣的朋友請參考!
公司簡介
Wearisma Taiwan 偀向軟體有限公司
總部位於英國倫敦,成立於2015年。
Wearisma Taiwan成立於2018年。
Wearisma partners with global premium and luxury brands and agencies to create meaningful and lasting connections. Founded by industry experts who specialise in growing global audiences, we built our products with insight into the way brands succeed. That’s why our Influencer discovery and management software is designed to help brands identify and build lasting relationships with influencers with the help of powerful analytics.
Wearisma is dissecting the world of social media and influencer marketing one platform at a time, supporting an illustrious roster of world-class clients who are market leaders in their respective fields from lifestyle, technology, beauty, fashion, automotive to art to be the innovators in influencer marketing.
職缺
全端工程師 x 2
徵才內容
We are looking for passionate developers who care about software excellence. You will join a small team of exceptional developers working in a fast-paced, startup environment to deliver world-class software.
The Full Stack Developer will serve a vital role designing and implementing new features and supporting existing ones.
You will work both independently and in the team to get features completed, working on all parts of the stack designing data models, algorithms and creating UIs.
Our tech stack includes MongoDB, Ruby, Elasticsearch, HTML5, CSS3, Javascript and Python. We have integrations with many social platforms and sync with massive amount of data.
We are also constantly experimenting with AI and data analysis to create useful insights for our users. The most successful experiments get integrated into the product.
工作內容
Design and implement features on platform
Write clean, maintainable and efficient code
Contribute in all phases of the development lifecycle
Work well with other developers, product owners and client support teams
薪資環境
月薪 TWD 70,000 - TWD 90,000
年終 2 - 3 個月
特休 15天,滿一年加一天
一年一次前往總公司交流
配Mac筆電
基本條件
資訊工程背景相關系所畢業,3年以上工作經驗
良好的英語會話與表達溝通能力及傑出的團隊合作
與國外同仁開會時,能接受彈性上班時間 (例如:12PM - 8PM)
致力於撰寫簡潔有效率、可讀性高、易於維護及測試的程式
加分條件
Experience working on software development projects using languages such as Ruby, Javascript, Java, C#, C++, Python
Experience document-oriented databases
Experience working with Agile approaches
Experience building beautiful front-end with HTML5 and CSS3
工作地點
近捷運善導寺站
工作時間
週一至週五 11am - 7pm
連絡方式
請將 CV 寄至 jobs@wearisma.com
elasticsearch client 在 The client noticed that the server is not a supported ... 的推薦與評價
... <看更多>
相關內容
elasticsearch client 在 Micronaut Elasticsearch 的推薦與評價
If you are creating your project using the Micronaut CLI, supply the elasticsearch feature to configure the Elasticsearch Java REST Client in your project:. ... <看更多>
elasticsearch client 在 Official Elasticsearch client library for Node.js - GitHub 的推薦與評價
Language clients are forward compatible; meaning that clients support communicating with greater or equal minor versions of Elasticsearch. Elasticsearch ... ... <看更多>