{"action":"created","issue":{"url":"https://api.github.com/repos/monkey/monkey/issues/205","labels_url":"https://api.github.com/repos/monkey/monkey/issues/205/labels{/name}","comments_url":"https://api.github.com/repos/monkey/monkey/issues/205/comments","events_url":"https://api.github.com/repos/monkey/monkey/issues/205/events","html_url":"https://github.com/monkey/monkey/issues/205","id":82271487,"number":205,"title":"Optimization suggestion to get rid of TCP_CORK","user":{"login":"neeraj9","id":809217,"avatar_url":"https://avatars.githubusercontent.com/u/809217?v=3","gravatar_id":"","url":"https://api.github.com/users/neeraj9","html_url":"https://github.com/neeraj9","followers_url":"https://api.github.com/users/neeraj9/followers","following_url":"https://api.github.com/users/neeraj9/following{/other_user}","gists_url":"https://api.github.com/users/neeraj9/gists{/gist_id}","starred_url":"https://api.github.com/users/neeraj9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neeraj9/subscriptions","organizations_url":"https://api.github.com/users/neeraj9/orgs","repos_url":"https://api.github.com/users/neeraj9/repos","events_url":"https://api.github.com/users/neeraj9/events{/privacy}","received_events_url":"https://api.github.com/users/neeraj9/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-29T05:29:05Z","updated_at":"2015-05-29T05:40:10Z","closed_at":null,"body":"I notice that you are using TCP_CORK on/off in various places. After spending some time looking at the static file serving it appears unnecessary. I suggest that you use sendto(2) interface with MSG_MORE instead (see http://linux.die.net/man/2/sendto for details). Note that this will save two system calls to setsockopt for TCP_CORK in you case while serving every request.\r\n\r\nI can work on a patch as well but it'l take some time since I just started going through the project.\r\n\r\nQuote from man sendto(2)\r\n\r\n> The caller has more data to send. This flag is used with TCP sockets to obtain the same\r\n> effect as the TCP_CORK socket option (see tcp(7)), with the difference that this flag can\r\n> be set on a per-call basis.\r\n\r\nExisting behavior:\r\n\r\n    setsockopt(TCP_CORK_ON)\r\n    writev(http_header)\r\n    sendfile()\r\n    setsockopt(TCP_CORK_OFF)\r\n\r\ninstead you should do the following:\r\n\r\nsendto(complete_http_header, MSG_MORE)\r\nsendfile()\r\n\r\nDrawbacks:\r\n\r\n* Instead of using writev(), you'll need to use sendto() which is not a vectorized so creating buffer for complete http header.\r\n\r\nAdvantages:\r\n\r\n* Reduced system call and less context switches between user-kernel.\r\n\r\n> The overhead of copy will be offset by use of fewer system call and\r\n> I think (though untested in your case) should do better.\r\n\r\nDisclaimer: I wrote my webserver and optimized to my hearts content only to realize that its missing a number of features. Now I am hunting for exiting projects to contribute instead. I found your project interesting (after evaluating quite a few open source available right now) and would like to contribute."},"comment":{"url":"https://api.github.com/repos/monkey/monkey/issues/comments/106696436","html_url":"https://github.com/monkey/monkey/issues/205#issuecomment-106696436","issue_url":"https://api.github.com/repos/monkey/monkey/issues/205","id":106696436,"user":{"login":"neeraj9","id":809217,"avatar_url":"https://avatars.githubusercontent.com/u/809217?v=3","gravatar_id":"","url":"https://api.github.com/users/neeraj9","html_url":"https://github.com/neeraj9","followers_url":"https://api.github.com/users/neeraj9/followers","following_url":"https://api.github.com/users/neeraj9/following{/other_user}","gists_url":"https://api.github.com/users/neeraj9/gists{/gist_id}","starred_url":"https://api.github.com/users/neeraj9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neeraj9/subscriptions","organizations_url":"https://api.github.com/users/neeraj9/orgs","repos_url":"https://api.github.com/users/neeraj9/repos","events_url":"https://api.github.com/users/neeraj9/events{/privacy}","received_events_url":"https://api.github.com/users/neeraj9/received_events","type":"User","site_admin":false},"created_at":"2015-05-29T05:40:10Z","updated_at":"2015-05-29T05:40:10Z","body":"@janus I was planning to push it out but then it needs a lot of improvement even for a first release. I will think about it, but not today."}}