Comparison

net/server_epoll.lua @ 11738:3f1450ec37f4

net.server_epoll: Improve efficiency of opportunistic writes Should prevent further opportunistic write attempts after the kernel buffers are full and stops accepting writes. When combined with `keep_buffers = false` it should stop it from repeatedly recreating the buffer table and concatenating it back into a string when there's a lot to write.
author Kim Alvefur <zash@zash.se>
date Sat, 14 Aug 2021 13:07:29 +0200
parent 11703:e57c5d9c722c
child 11741:dcf38ac6a38c
comparison
equal deleted inserted replaced
11737:59cf555b4698 11738:3f1450ec37f4
482 else 482 else
483 data = buffer[1] or ""; 483 data = buffer[1] or "";
484 end 484 end
485 end 485 end
486 local ok, err, partial = self.conn:send(data); 486 local ok, err, partial = self.conn:send(data);
487 self._writable = ok;
487 if ok then 488 if ok then
488 self:set(nil, false); 489 self:set(nil, false);
489 if cfg.keep_buffers and type(buffer) == "table" then 490 if cfg.keep_buffers and type(buffer) == "table" then
490 for i = #buffer, 1, -1 do 491 for i = #buffer, 1, -1 do
491 buffer[i] = nil; 492 buffer[i] = nil;
537 self.writebuffer = { buffer, data }; 538 self.writebuffer = { buffer, data };
538 elseif buffer == nil then 539 elseif buffer == nil then
539 self.writebuffer = data; 540 self.writebuffer = data;
540 end 541 end
541 if not self._write_lock then 542 if not self._write_lock then
542 if cfg.opportunistic_writes and not self._opportunistic_write then 543 if self._writable and cfg.opportunistic_writes and not self._opportunistic_write then
543 self._opportunistic_write = true; 544 self._opportunistic_write = true;
544 local ret, err = self:onwritable(); 545 local ret, err = self:onwritable();
545 self._opportunistic_write = nil; 546 self._opportunistic_write = nil;
546 return ret, err; 547 return ret, err;
547 end 548 end
743 return; 744 return;
744 end 745 end
745 local client = wrapsocket(conn, self, nil, self.listeners); 746 local client = wrapsocket(conn, self, nil, self.listeners);
746 client:debug("New connection %s on server %s", client, self); 747 client:debug("New connection %s on server %s", client, self);
747 client:defaultoptions(); 748 client:defaultoptions();
749 client._writable = cfg.opportunistic_writes;
748 if self.tls_direct then 750 if self.tls_direct then
749 client:add(true, true); 751 client:add(true, true);
750 client:inittls(self.tls_ctx, true); 752 client:inittls(self.tls_ctx, true);
751 else 753 else
752 client:add(true, false); 754 client:add(true, false);