Comparison

net/server_epoll.lua @ 10228:e77bf4222fae

net.server_epoll: Add support for opportunistic writes This tries to flush data to the underlying sockets when receiving writes. This should lead to fewer timer objects being around. On the other hand, this leads to more and smaller writes which may translate to more TCP/IP packets being sent, depending on how the kernel handles this. This trades throughput for lower latency.
author Kim Alvefur <zash@zash.se>
date Wed, 28 Aug 2019 01:41:00 +0200
parent 10098:dda1c7ccb209
child 10233:600eee3c4752
comparison
equal deleted inserted replaced
10227:eeb711b92da5 10228:e77bf4222fae
64 min_wait = 1e-06; 64 min_wait = 1e-06;
65 65
66 -- EXPERIMENTAL 66 -- EXPERIMENTAL
67 -- Whether to kill connections in case of callback errors. 67 -- Whether to kill connections in case of callback errors.
68 fatal_errors = false; 68 fatal_errors = false;
69
70 -- Attempt writes instantly
71 opportunistic_writes = false;
69 }}; 72 }};
70 local cfg = default_config.__index; 73 local cfg = default_config.__index;
71 74
72 local fds = createtable(10, 0); -- FD -> conn 75 local fds = createtable(10, 0); -- FD -> conn
73 76
411 elseif partial then 414 elseif partial then
412 buffer[1] = data:sub(partial+1); 415 buffer[1] = data:sub(partial+1);
413 for i = #buffer, 2, -1 do 416 for i = #buffer, 2, -1 do
414 buffer[i] = nil; 417 buffer[i] = nil;
415 end 418 end
419 self:set(nil, true);
416 self:setwritetimeout(); 420 self:setwritetimeout();
417 end 421 end
418 if err == "wantwrite" or err == "timeout" then 422 if err == "wantwrite" or err == "timeout" then
419 self:set(nil, true); 423 self:set(nil, true);
420 elseif err == "wantread" then 424 elseif err == "wantread" then
437 t_insert(buffer, data); 441 t_insert(buffer, data);
438 else 442 else
439 self.writebuffer = { data }; 443 self.writebuffer = { data };
440 end 444 end
441 if not self._write_lock then 445 if not self._write_lock then
446 if cfg.opportunistic_writes then
447 self:onwritable();
448 return #data;
449 end
442 self:setwritetimeout(); 450 self:setwritetimeout();
443 self:set(nil, true); 451 self:set(nil, true);
444 end 452 end
445 return #data; 453 return #data;
446 end 454 end