批量put和单条put
生活随笔
收集整理的這篇文章主要介紹了
批量put和单条put
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
Hbase1.1.5源碼:
HTable類:
@Overridepublic void put(final Put put) throws IOException {getBufferedMutator().mutate(put);//放入bufferMutator中if (autoFlush) {flushCommits();}}/*** {@inheritDoc}* @throws IOException*/@Overridepublic void put(final List<Put> puts) throws IOException {getBufferedMutator().mutate(puts);放入bufferMutator中if (autoFlush) {flushCommits();}}BufferedMutatorImpl類:
@Overridepublic synchronized void mutate(Mutation m) throws InterruptedIOException,RetriesExhaustedWithDetailsException {doMutate(m);}@Overridepublic synchronized void mutate(List<? extends Mutation> ms) throws InterruptedIOException,RetriesExhaustedWithDetailsException {for (Mutation m : ms) {doMutate(m); //調用單條的mutate方法}}private void doMutate(Mutation m) throws InterruptedIOException,RetriesExhaustedWithDetailsException {if (closed) {throw new IllegalStateException("Cannot put when the BufferedMutator is closed.");}if (!(m instanceof Put) && !(m instanceof Delete)) {throw new IllegalArgumentException("Pass a Delete or a Put");}// This behavior is highly non-intuitive... it does not protect us against// 94-incompatible behavior, which is a timing issue because hasError, the below code// and setter of hasError are not synchronized. Perhaps it should be removed.if (ap.hasError()) {writeAsyncBuffer.add(m);backgroundFlushCommits(true);}if (m instanceof Put) {validatePut((Put) m);}currentWriteBufferSize += m.heapSize(); // 計算字節(jié)大小,并累加writeAsyncBuffer.add(m);// 如果當前的數據字節(jié)大小大于閾值,則進行commitwhile (currentWriteBufferSize > writeBufferSize) {backgroundFlushCommits(false);}} ?疑問:如果 設置了autoFlush 為false, 則批量put和單條put的效率應該是一樣的。為什么在測試時,批量要比單條快很多??
轉載于:https://my.oschina.net/u/1537182/blog/702840
總結
以上是生活随笔為你收集整理的批量put和单条put的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OPPO回应将裁撤电视业务线:业务正常运
- 下一篇: 实现OC与JS的交互