Eroiko
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
###### tags: `database` # Assignment 4 report 1 組員: 109062274, 109062314, 109062315 ## 概述 本次我們實作非常多優化,主要以並行上的優化為主。我們為每一項完整的優化設定一個 branch (以 `feat` 開頭),使實驗可以透過 merge 各個 branch 完成。 優化的功能列序如下。 * File Package * `featRWFileMgr`: 以 `StampedLock` 優化讀寫同步化 * `featBlockId`: 簡化計算固定 `hashCode` 與 `toString` 行為 * `featPage`: 以 `ReentrantLock` 優化讀寫同步化,並減少寫入次數 * Buffer Package * `featBufMgrWaitQueue`: 優化 waiting queue 的行為 * `featBuffer`、`BufferPoolMgr`: 移除不必要的同步機制 以下針對各項進行說明;另外由於我們的 commit 說明都頗清楚,所以其實可以直接閱讀得知實作細節。 ## Buffer Package ### `BufferPoolMgr` 對 `BufferPoolMgr` 的優化主要是把其 method 拿掉 `synchronized`。並在其 data member 加上 lock,或把 data member 改成 `Atomic`。 #### `Buffer::pin(BlockId blk)` * 優化 : 把 `synchronized` 拿掉,希望多個 thread 可以 pin `bufferPool`,但沒有過testcase所以維持synchronized。 * 想法 : 我們不希望當一個 thread 在 swap out block 的時候,另一個 thread 想要 pin 同一個 `Buffer` (或是也想 swap out 同一個 `Buffer`)。因此,我們的做法是根據每一個不同的 `Buffer` 上一個 lock (用 `Buffer::isSwapLock()` 取得該lock)。首先找尋 `bufferPool` 有沒有 hit 同一個 block , 如果沒有再找尋哪一個 `Buffer` 沒被 pin 過,我們也加 `buffer.isSwapLock().tryLock()` 條件來判斷是否這個buffer 正在 swapping,沒有的話才能取得 `Buffer` 的 lock 並做 swapping。如果有 hit 同一個 block,我們還是要取得此 `Buffer` 的 lock,因為有可能同時另一個 thread 想要做 swapping,這樣會造成 Buffer 中的 blockId 造成不一致。 ### `BufferMgr` * Implement loose FIFO algorithm > not just wake up the fist element in waiting queue, but with `WAKE_RATIO` parameter, 0 means strict FIFO mode, to decide the ratio in queue to wake up from head 即我們不希望嚴格的 FIFO,改實作為允許當喚醒由 `WAKE_RATIO` 外部參數決定之區間大小時皆可繼續執行的邏輯。 * Reduce critical section > the `synchronized` keyword only contain the operaions of bufferPool ### `Buffer` * Use atomic integer to get rid of monitor method > * transform variable `pins` into `AtomicInteger` * Remove unneeded monitors > * `getVal/setVal` is based on thread-safe `page` > * `flush` is based on given lock > * others are just returning member reference ## File Package ### `Page` * Remove monitor of `read/write/append` > * since `FileMgr` is thread-safe * Restrict CS of `getVal/setVal` using lock > * Create lock member to protect `content-related` section > * Use `ByteBuffer` to reduce time of write `content` in `setVal` ### `FileMgr` * Replace plain `IoChannel` with self-defined data structure `LockableFile` > file: original `IoChannel` object sl: `StampedLock` as lock with read optimization deleted: atomic boolean mark to check whether a file is deleted * Optimize readonly attribute > No synchronization/lock needed for isNew attribute, make it readonly * Use Java Stampedlock > * Read method: use pessimistic read > * Size method: use very-optimistic read > * Write & delete method: use write lock ### `BlockId` 調整使 `hashCode` 和 `toString` 方法可以直接取出恆定的計算結果: 將該恆定的計算結果於建構時計算並保留於成員。 ## 實驗 ### 實驗介紹與準備 將實驗略分為三組: 1. branch `optFilePackage`: 包含所有與 `File` package 有關的優化。 2. branch `optBufferPackage`: 包含所有與 `Buffer` package 相關的優化。 3. branch `release`: 整合所有優化。 對照組為 `dev`,其只包含與環境設定相關的調整 (Makefile 等)。 我們使用 `Micro Bench` 進行實驗,針對本次作業的六個可調參數分別進行遍歷: * `BUFFER_POOL_SIZE`: 50, 500, 5000 * `RW_TX_RATE`: 0.0, 0.5, 1 * `TOTAL_READ_COUNT`: 10, 20 * `LOCAL_HOT_COUNT`: 2, 10 * `WRITE_RATIO_IN_RW_TX`: 0., 0.5, 1. * `HOT_CONFLICT_RATE`: 0.001, 0.01 使用 Python + Makefile 撰寫腳本進行實驗與數據搜集,共實驗了216種實驗結果。 ### 實驗環境 |CPU|RAM|Disk|OS| |:-:|:-:|:-:|:-:| |Intel Core i3-12100 3.3GHz|16GB|512GB SSD|Ubuntu 22.04| ### 實驗分析 我們以高壓以及低壓測試進行分析,各個測試採3種參數來分析及佐證我們的優化效果,對照組為`dev`。最後再根據216種實驗結果,找出整體優化效果平均與最好的數值及該參數之設定 #### 高壓測試 |Parameter Name|Buffer Pool Size|RW TX rate|Total Read Count|Local Hot Count|Write Ratio in RW TX|Hot Conflict Rate| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| |High Pressure1|50|1|20|2|1|0.01| |High Pressure2|50|1|20|10|1|0.01| |High Pressure3|500|1|20|10|1|0.01| #### 高壓測試結果 |Type|Throughput (Higher Better)|Latency (Lower Better)| |:-:|:-:|:-:| |High Pressure1|![](https://hackmd.io/_uploads/ByVbgWAVh.png)|![](https://hackmd.io/_uploads/SyoBJZRE3.png)| |High Pressure2|![](https://hackmd.io/_uploads/H1jVxWRNn.png)|![](https://hackmd.io/_uploads/BJghJZRNh.png)| |High Pressure3|![](https://hackmd.io/_uploads/rkoUxZCEn.png)|![](https://hackmd.io/_uploads/BJxTy-CNh.png)| #### 低壓測試 (為了凸顯優化效果,BufferPool size 固定為 50) |Parameter Name|Buffer Pool Size|RW TX rate|Total Read Count|Local Hot Count|Write Ratio in RW TX|Hot Conflict Rate| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| |Low Pressure1|50|0|10|10|0|0.001| |Low Pressure2|50|0|20|2|0|0.001| |Low Pressure3|50|0.5|10|10|0.5|0.001| #### 低壓測試結果 |Type|Throughput (Higher Better)|Latency (Lower Better)| |:-:|:-:|:-:| |Low Pressure1|![](https://hackmd.io/_uploads/rkxQigAEh.png)|![](https://hackmd.io/_uploads/B1U7jgC4h.png)| |Low Pressure2|![](https://hackmd.io/_uploads/BycrslCN3.png)|![](https://hackmd.io/_uploads/H1pHoe04h.png)| |Low Pressure3|![](https://hackmd.io/_uploads/rkEUoe0Vn.png)|![](https://hackmd.io/_uploads/H1O8ieCVh.png)| #### 整體優化效果 (Average perfomance) 我們寫一個 python script 來分析 optFilePackage、optBufferPackage 以及 release 對比對照組 dev 實驗結果,總共 216 種參數設定。 | Optimizaton Level | Committed提升(%) | Avg Latency減少(%) | |:-:|:-:|:-:| | optBufferPackage | 10.23 | 8.26 | | optFilePackage | 50.16 | 29.13 | | release | 57.26 | 29.81 ![](https://hackmd.io/_uploads/rk4b-M043.png) <!-- #### Buffer優化率高於100%的參數設定 |Condition|Buffer Pool Size|RW TX rate|Total Read Count|Local Hot Count|Write Ratio in RW TX|Hot Conflict Rate| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| |1|50|0.5|10|10|0.5|0.01| |2|500|0.5|10|10|0.5|0.001| |3|5000|0.5|10|10|0.5|0.001| |4|5000|1|20|2|0|0.001| (buffer沒值代表優化率小於100%) ![](https://hackmd.io/_uploads/HJFQFzCN2.png) --> #### 實驗分析解釋 * 高壓測試 可以看到 optFilePackage 和 release 有明顯提升,但 optBufferPackage 跟 dev 沒相差多少,這是因為在 `BufferPoolMgr` 中跟 `pin()` 和 `unpin()` 相關的 method 沒有把 synchronized 拿掉,而造成 bottleneck,多個 thread 不能併行執行 `pin` `unpin`。在高壓測試中,這個 bottleneck 會更加明顯,我們較看不到 optBufferPackage 的優化。 * 低壓測試 前兩個參數設定以沒有 write 操作為原則去調整其他參數,可以發現 `Buffer package` 的優化有差不多 20% 的提升,而 `File package` 的優化有差不多 30% 的提升,而兩種優化合起來可以有多達 40% 的提升。而第三種參數設定多了些 write 操作,相比 `dev` 和 `Buffer package` 有了 70% 的提升,代表我們在 `File package` 對讀寫操作的優化十分成功。 * 整體優化效果 這裡將 216 種參數設定得出的優化效果取平均值,可以發現我們`File package` 的優化效果竟然高達 50%,而之所以可以提升這麼多,是因為我們特別針對同時多個讀、單一個寫、進行讀時會採用 Optimistic read 去進行優化,並對一些 `BlockID` 的內容提前進行計算等等,使得這部分的效能提升非常多。而 `Buffer package` 僅只有 10% 的提升,原因大致上就是我們對`BufferPoolMgr` 中跟 `pin()` 和 `unpin()` 的優化沒有處理恰當,如同高壓測試中所提到的描述。而整體看下來,最後合併版本 `release` 的 throughput 提升率多達快 60%,且 latency 也減少了快 30%,可以看出此次的實作效果十分成功。 <!-- 我們把synchronized method 拿掉,這樣可以讓多個 thread 並行執行 object 的 method,而非取得object的monitor才能執行method。因此我們的方法比原始版本更能增加 throughput ,減少 latency。 可以看到 optFilePackage 和 release 有明顯提升,但 optBufferPackage 跟 dev 沒相差多少,這是因為在 `BufferPoolMgr` 中跟 `pin()` 和 `unpin()` 相關的 method 沒有把 synchronized 拿掉,而造成 bottleneck,多個 thread 不能併行執行 `pin` `unpin`。在高壓測試中,這個 bottleneck 會更加明顯,我們較看不到 optBufferPackage 的優化。但在低壓測試中,buffer `pin` `unpin` 的 bottleneck 會較不明顯。因此在低壓環境中較可以看到 optBufferPackage 的優化,反之叫看不太到。 而optFilePackage之所以可以提升這麼多,是因為我們可以同時多個讀、單一個寫,且進行讀時會採用 Optimistic read,並針對一些 `BlockID` 的內容提前進行計算等等,使得這部分的效能提升非常多。 -->

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully