Skip to content
Peter V. Saveliev edited this page May 14, 2016 · 5 revisions
  • RX path
    • avoid buffer copying
      • (+) socket.recv_into()
      • (+) struct.unpack_from()
    • (+) NLA fast tracks: zstring, string, packed (+nla), generic (+nla)
    • (+) cache lookups instead of unpack() for NLA headers
  • TX path
    • (!) bottleneck: socket.sendto():
Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    76                                               @profile
    77                                               def _gate(self, msg, addr):
    78       230         1549      6.7      0.2          msg.reset()
    79       230        60965    265.1      6.5          msg.encode()
    80       230        11351     49.4      1.2          ret = self._sproxy.handle(msg)
    81       230          524      2.3      0.1          if ret is not None:
    82       100          222      2.2      0.0              if ret['verdict'] == 'forward':
    83       100       406408   4064.1     43.6                  return self._sendto(ret['data'], addr)
    84                                                       elif ret['verdict'] in ('return', 'error'):
    85                                                           if self._s_channel is not None:
    86                                                               return self._s_channel.send(ret['data'])
    87                                                           else:
    88                                                               msgs = self.marshal.parse(ret['data'])
    89                                                               for msg in msgs:
    90                                                                   seq = msg['header']['sequence_number']
    91                                                                   if seq in self.backlog:
    92                                                                       self.backlog[seq].append(msg)
    93                                                                   else:
    94                                                                       self.backlog[seq] = [msg]
    95                                                               return len(ret['data'])
    96                                                       else:
    97                                                           ValueError('Incorrect verdict')
    98                                           
    99       130       450966   3469.0     48.4          return self._sendto(msg.data, addr)
Clone this wiki locally