proxygen
proxygen::compress::QPACKScheme Class Reference

#include <QPACKScheme.h>

Inheritance diagram for proxygen::compress::QPACKScheme:
proxygen::compress::CompressionScheme folly::EventBase::LoopCallback

Classes

struct  QPACKAck
 

Public Member Functions

 QPACKScheme (CompressionSimulator *sim, uint32_t tableSize, uint32_t maxBlocking)
 
 ~QPACKScheme ()
 
std::unique_ptr< AckgetAck (uint16_t seqn) override
 
void recvAck (std::unique_ptr< Ack > ack) override
 
std::pair< FrameFlags, std::unique_ptr< folly::IOBuf > > encode (bool, std::vector< compress::Header > allHeaders, SimStats &stats) override
 
void decode (FrameFlags flags, std::unique_ptr< folly::IOBuf > encodedReq, SimStats &stats, SimStreamingCallback &callback) override
 
uint32_t getHolBlockCount () const override
 
- Public Member Functions inherited from proxygen::compress::CompressionScheme
 CompressionScheme (CompressionSimulator *sim)
 
virtual ~CompressionScheme ()
 
void runLoopCallback () noexceptoverride
 
- Public Member Functions inherited from folly::EventBase::LoopCallback
virtual ~LoopCallback ()=default
 
void cancelLoopCallback ()
 
bool isLoopCallbackScheduled () const
 

Public Attributes

QPACKCodec client_
 
QPACKCodec server_
 
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > controlQueue_
 
uint16_t encodeControlIndex_ {0}
 
uint16_t decodeControlIndex_ {0}
 
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > acks_
 
uint16_t sendAck_ {1}
 
uint16_t recvAck_ {1}
 
- Public Attributes inherited from proxygen::compress::CompressionScheme
std::list< BlockInfoencodedBlocks
 
std::list< BlockInfopacketBlocks
 
size_t index {0}
 
std::chrono::milliseconds prev
 
size_t packetBytes {0}
 
std::chrono::milliseconds decodeDelay
 
std::list< uint16_tpacketIndices
 

Additional Inherited Members

- Public Types inherited from proxygen::compress::CompressionScheme
using BlockInfo = std::tuple< FrameFlags, bool, std::unique_ptr< folly::IOBuf >, SimStreamingCallback * >
 

Detailed Description

Definition at line 18 of file QPACKScheme.h.

Constructor & Destructor Documentation

proxygen::compress::QPACKScheme::QPACKScheme ( CompressionSimulator sim,
uint32_t  tableSize,
uint32_t  maxBlocking 
)
inlineexplicit

Definition at line 20 of file QPACKScheme.h.

References client_, proxygen::NoPathIndexingStrategy::getInstance(), server_, proxygen::QPACKCodec::setDecoderHeaderTableMaxSize(), proxygen::QPACKCodec::setEncoderHeaderTableSize(), proxygen::QPACKCodec::setHeaderIndexingStrategy(), proxygen::QPACKCodec::setMaxBlocking(), and proxygen::QPACKCodec::setMaxVulnerable().

22  : CompressionScheme(sim) {
27  client_.setMaxVulnerable(maxBlocking);
28  server_.setMaxBlocking(maxBlocking);
29  }
void setMaxVulnerable(uint32_t maxVulnerable)
Definition: QPACKCodec.h:121
void setDecoderHeaderTableMaxSize(uint32_t size)
Definition: QPACKCodec.h:62
static const NoPathIndexingStrategy * getInstance()
void setMaxBlocking(uint32_t maxBlocking)
Definition: QPACKCodec.h:125
void setHeaderIndexingStrategy(const HeaderIndexingStrategy *indexingStrat)
Definition: QPACKCodec.h:106
CompressionScheme(CompressionSimulator *sim)
void setEncoderHeaderTableSize(uint32_t size)
Definition: QPACKCodec.h:58
proxygen::compress::QPACKScheme::~QPACKScheme ( )
inline

Definition at line 31 of file QPACKScheme.h.

References proxygen::QPACKCodec::getQueuedBytes(), and server_.

31  {
32  CHECK_EQ(server_.getQueuedBytes(), 0);
33  }
uint64_t getQueuedBytes() const
Definition: QPACKCodec.h:117

Member Function Documentation

void proxygen::compress::QPACKScheme::decode ( FrameFlags  flags,
std::unique_ptr< folly::IOBuf encodedReq,
SimStats stats,
SimStreamingCallback callback 
)
inlineoverridevirtual

Implements proxygen::compress::CompressionScheme.

Definition at line 115 of file QPACKScheme.h.

References proxygen::compress::FrameFlags::allowOOO, folly::IOBufQueue::append(), controlQueue_, decodeControlIndex_, proxygen::QPACKCodec::decodeEncoderStream(), proxygen::QPACKCodec::decodeStreaming(), proxygen::QPACKCodec::getQueuedBytes(), proxygen::compress::SimStats::maxQueueBufferBytes, proxygen::compress::SimStreamingCallback::maybeMarkHolDelay(), folly::gen::move, folly::io::detail::CursorBase< Derived, BufType >::readBE(), proxygen::compress::SimStreamingCallback::requestIndex, proxygen::compress::QPACKScheme::QPACKAck::seqn, proxygen::compress::SimStreamingCallback::seqn, server_, uint16_t, and uint32_t.

118  {
119  folly::io::Cursor cursor(encodedReq.get());
120  auto toTrim = sizeof(uint16_t) * 3;
121  auto len = cursor.readBE<uint16_t>();
122  if (len > 0) {
123  // check decode result
124  auto controlIndex = cursor.readBE<uint16_t>();
125  toTrim += sizeof(uint16_t);
126  std::unique_ptr<folly::IOBuf> control;
127  cursor.clone(control, len);
128  if (controlIndex == decodeControlIndex_) {
129  // next expected control block, decode
130  VLOG(5) << "decode controlIndex=" << controlIndex;
133  while (!controlQueue_.empty() &&
134  controlQueue_.begin()->first == decodeControlIndex_) {
135  // drain the queue
136  VLOG(5) << "decode controlIndex=" << controlQueue_.begin()->first;
137  auto it = controlQueue_.begin();
140  controlQueue_.erase(it);
141  }
142  } else {
143  // out of order control block, queue it
144  controlQueue_.emplace(controlIndex, std::move(control));
145  }
146  toTrim += len;
147  }
148  auto seqn = cursor.readBE<uint16_t>();
149  callback.seqn = seqn;
150  VLOG(1) << "Decoding request=" << callback.requestIndex
151  << " header seqn=" << seqn
152  << " allowOOO=" << uint32_t(flags.allowOOO);
153  len = cursor.readBE<uint16_t>();
154  folly::IOBufQueue queue;
155  queue.append(std::move(encodedReq));
156  queue.trimStart(toTrim);
157  server_.decodeStreaming(seqn, queue.move(), len, &callback);
158  callback.maybeMarkHolDelay();
159  if (server_.getQueuedBytes() > stats.maxQueueBufferBytes) {
160  stats.maxQueueBufferBytes = server_.getQueuedBytes();
161  }
162  }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
flags
Definition: http_parser.h:127
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > controlQueue_
Definition: QPACKScheme.h:170
HPACK::DecodeError decodeEncoderStream(std::unique_ptr< folly::IOBuf > buf)
Definition: QPACKCodec.h:45
uint64_t getQueuedBytes() const
Definition: QPACKCodec.h:117
void decodeStreaming(uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t length, HPACK::StreamingCallback *streamingCb) noexcept
Definition: QPACKCodec.cpp:56
std::pair<FrameFlags, std::unique_ptr<folly::IOBuf> > proxygen::compress::QPACKScheme::encode ( bool  ,
std::vector< compress::Header allHeaders,
SimStats stats 
)
inlineoverridevirtual

Implements proxygen::compress::CompressionScheme.

Definition at line 81 of file QPACKScheme.h.

References client_, wangle::HTTPHeaderSize::compressed, proxygen::compress::SimStats::compressed, proxygen::QPACKCodec::encode(), encodeControlIndex_, proxygen::HeaderCodec::getEncodedSize(), proxygen::compress::CompressionScheme::index, folly::io::QueueAppender::insert(), folly::IOBufQueue::move(), folly::gen::move, uint16_t, uint32_t, proxygen::compress::SimStats::uncompressed, wangle::HTTPHeaderSize::uncompressed, and folly::io::detail::Writable< Derived >::writeBE().

84  {
85  index++;
86  auto result = client_.encode(allHeaders, index);
87  uint16_t len = 0;
88  folly::IOBufQueue queue;
89  static const uint32_t growth = 1400; // chosen arbitrarily
90  folly::io::QueueAppender cursor(&queue, growth);
91  if (result.control) {
92  VLOG(5) << "Writing encodeControlIndex_=" << encodeControlIndex_;
93  len = result.control->computeChainDataLength();
94  cursor.writeBE<uint16_t>(len);
95  cursor.writeBE<uint16_t>(encodeControlIndex_++);
96  cursor.insert(std::move(result.control));
97  // Don't count the framing against the compression ratio, for now
98  // stats.compressed += 3 * sizeof(uint16_t);
99  } else {
100  cursor.writeBE<uint16_t>(0);
101  }
102  if (result.stream) {
103  len = result.stream->computeChainDataLength();
104  }
105  cursor.writeBE<uint16_t>(index);
106  cursor.writeBE<uint16_t>(len);
107  cursor.insert(std::move(result.stream));
108  stats.uncompressed += client_.getEncodedSize().uncompressed;
109  stats.compressed += client_.getEncodedSize().compressed;
110  // OOO is allowed if there has not been an eviction
111  FrameFlags flags(false, false);
112  return {flags, queue.move()};
113  }
flags
Definition: http_parser.h:127
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
QPACKEncoder::EncodeResult encode(std::vector< compress::Header > &headers, uint64_t id) noexcept
Definition: QPACKCodec.cpp:47
const HTTPHeaderSize & getEncodedSize()
Definition: HeaderCodec.h:62
std::unique_ptr<Ack> proxygen::compress::QPACKScheme::getAck ( uint16_t  seqn)
inlineoverridevirtual

Implements proxygen::compress::CompressionScheme.

Definition at line 51 of file QPACKScheme.h.

References proxygen::QPACKCodec::encodeHeaderAck(), proxygen::QPACKCodec::encodeTableStateSync(), folly::gen::move, sendAck_, proxygen::compress::QPACKScheme::QPACKAck::seqn, and server_.

51  {
52  VLOG(4) << "Sending ack for seqn=" << seqn;
53  auto res = std::make_unique<QPACKAck>(seqn, sendAck_++,
56  return std::move(res);
57  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > encodeHeaderAck(uint64_t streamId)
Definition: QPACKCodec.h:82
std::unique_ptr< folly::IOBuf > encodeTableStateSync()
Definition: QPACKCodec.h:78
uint32_t proxygen::compress::QPACKScheme::getHolBlockCount ( ) const
inlineoverridevirtual

Implements proxygen::compress::CompressionScheme.

Definition at line 164 of file QPACKScheme.h.

References proxygen::QPACKCodec::getHolBlockCount(), and server_.

164  {
165  return server_.getHolBlockCount();
166  }
uint64_t getHolBlockCount() const
Definition: QPACKCodec.h:113
void proxygen::compress::QPACKScheme::recvAck ( std::unique_ptr< Ack ack)
inlineoverridevirtual

Implements proxygen::compress::CompressionScheme.

Definition at line 58 of file QPACKScheme.h.

References acks_, client_, proxygen::QPACKCodec::decodeDecoderStream(), folly::gen::move, proxygen::HPACK::NONE, and recvAck_.

58  {
59  CHECK(ack);
60  auto qpackAck = dynamic_cast<QPACKAck*>(ack.get());
61  CHECK_NOTNULL(qpackAck);
62  VLOG(4) << "Received ack for seqn=" << qpackAck->seqn;
63  CHECK(qpackAck->headerAck);
64  if (qpackAck->controlAck) {
65  qpackAck->headerAck->prependChain(std::move(qpackAck->controlAck));
66  }
67  // The decoder stream must be processed in order
68  acks_.emplace(qpackAck->ackSeqn, std::move(qpackAck->headerAck));
69  do {
70  auto it = acks_.begin();
71  if (it->first != recvAck_) {
72  break;
73  }
74  CHECK_EQ(client_.decodeDecoderStream(std::move(it->second)),
76  recvAck_++;
77  acks_.erase(it);
78  } while (!acks_.empty());
79  }
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > acks_
Definition: QPACKScheme.h:173
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
HPACK::DecodeError decodeDecoderStream(std::unique_ptr< folly::IOBuf > buf)
Definition: QPACKCodec.h:67

Member Data Documentation

std::map<uint16_t, std::unique_ptr<folly::IOBuf> > proxygen::compress::QPACKScheme::acks_

Definition at line 173 of file QPACKScheme.h.

Referenced by recvAck().

QPACKCodec proxygen::compress::QPACKScheme::client_

Definition at line 168 of file QPACKScheme.h.

Referenced by encode(), QPACKScheme(), and recvAck().

std::map<uint16_t, std::unique_ptr<folly::IOBuf> > proxygen::compress::QPACKScheme::controlQueue_

Definition at line 170 of file QPACKScheme.h.

Referenced by decode().

uint16_t proxygen::compress::QPACKScheme::decodeControlIndex_ {0}

Definition at line 172 of file QPACKScheme.h.

Referenced by decode().

uint16_t proxygen::compress::QPACKScheme::encodeControlIndex_ {0}

Definition at line 171 of file QPACKScheme.h.

Referenced by encode().

uint16_t proxygen::compress::QPACKScheme::recvAck_ {1}

Definition at line 175 of file QPACKScheme.h.

Referenced by recvAck().

uint16_t proxygen::compress::QPACKScheme::sendAck_ {1}

Definition at line 174 of file QPACKScheme.h.

Referenced by getAck().

QPACKCodec proxygen::compress::QPACKScheme::server_

Definition at line 169 of file QPACKScheme.h.

Referenced by decode(), getAck(), getHolBlockCount(), QPACKScheme(), and ~QPACKScheme().


The documentation for this class was generated from the following file: