Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

減少不必要的資料庫空間消耗 #35

Open
3 tasks
ddio opened this issue Jul 1, 2019 · 0 comments
Open
3 tasks

減少不必要的資料庫空間消耗 #35

ddio opened this issue Jul 1, 2019 · 0 comments
Assignees

Comments

@ddio
Copy link
Contributor

ddio commented Jul 1, 2019

一開始為了簡化邏輯,把原始資料、結構化資料、歷史資料全都塞在資料庫裡,導致資料庫以每週 1.5G 的速度吃掉硬碟,但其實裡面大部分的東西,都是沒有用的。

目前資料庫裡會被用到的 tables

  1. house - 爬蟲讀、定期匯出
  2. house_etc - 重跑 parser 時的資料來源、客製化匯出時可能會用到個別平台的欄位
  3. house_ts - syncstateful 會拿來判斷物件花多久出租,須保留過去 60 天資料,確定儲存完整的 591 開放週期

沒有用到的 tables

  1. house_ts - 60 天以上的資料,根據 591 的設定,目前完全沒用到,但之後若擴充到其他平台時,則不一定,較好的方式是把需要歷史資料判斷的欄位分開存放
  2. house_etc - 一年以上的資料,基本上匯出時用不到,而且也不會被搜尋,所以完全不用資料庫儲存也可以

計畫

因為這兩個 table 在爬蟲進行時,還是會有頻繁的修改,所以在爬的時候,還是需要存在,所以:

  • 把 house_ts 和 house_etc 放到 file system / S3 ,減少資料庫的空間與費用
  • 透過 django command ,在每日工作結束後,把沒用到的資料搬到 file system 中

目前所佔空間:
2019-07-01 18-42-24 的螢幕擷圖

  1. Phase I - 60 日以上的 house_ts
    • 預計可以減少 47G ,約 40% 的空間
    • 因為每日空間增加量幾乎固定,預計減少 50%
  2. Phase II - 一歲以上的 house_etc ,匯出還是依賴資料庫
    • 預計可以減少 20G ,約 20% 的空間
    • 因為每日空間增加量幾乎固定,做完可減少所有 house_etc 的增幅,預計減少 40%
  3. Phase III - 所有的 house_etc
    • 預計可以減少 20G ,約 20% 的空間
ddio added a commit that referenced this issue Aug 16, 2019
ddio added a commit that referenced this issue Aug 16, 2019
ddio added a commit that referenced this issue Aug 16, 2019
ddio added a commit that referenced this issue Aug 16, 2019
Add pagination to lower memory usage, #35
ddio added a commit that referenced this issue Aug 17, 2019
Fix wrong cursor usage and add tgz packaging to reduce file size, #35
ddio added a commit that referenced this issue Aug 17, 2019
@ddio ddio self-assigned this Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant