Date: Tue, 3 Jul 2018 00:53:28 +1200 From: Thomas Munro <munro@ip9.org> To: freebsd-hackers@freebsd.org Subject: Patching setproctitle() to go faster, for PostgreSQL Message-ID: <CADLWmXWCj_WgYfQfzUL_aFLYYqezmbivzF=gKyk%2B6JqPcBvbXQ@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
--00000000000023a918057003afda Content-Type: text/plain; charset="UTF-8" Hi FreeBSD hackers, PostgreSQL's update_process_titles setting, which defaults to on, slows busy databases down quite noticeably on FreeBSD and so a lot of people turn it off. Having that information in ps/top/htop is nice, so I don't like turning it off. It was a rainy Sunday here yesterday so I decided to hack on that. I wrote an experimental patch, attached, that essentially reverts to the ancient syscall-free BSD behaviour (?) on a per-process basis, for processes that are update-heavy. That raises some interesting questions about torn reads, I admit... I didn't see much difference in "pgbench" on my laptop, but on an AWS m4.10xlarge (40 vCPU) machine I could easily see a difference. I think there is probably a contention effect somewhere that gets worse with more concurrency. pgbench -i -s 10 postgres pgbench -T60 -c 40 -j 40 -S -M prepared postgres Stock 11.2, update_process_titles = on: 472873 TPS (default) Stock 11.2, update_process_titles = off: 539391 TPS (~13% faster than default) Patched 11.2, update_process_titles = on: 519733 TPS (~10% faster than default) I'd be grateful for any feedback. Thanks, Thomas Munro --00000000000023a918057003afda Content-Type: application/octet-stream; name="0001-Speed-up-setproctitle-for-frequent-callers.patch" Content-Disposition: attachment; filename="0001-Speed-up-setproctitle-for-frequent-callers.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_jj48xgmm0 RnJvbSBlZjkzOGY1YWNmYTM4ZDIwZDVkYTYzMGVkYjE4Mzg3YWRkMTE2MDUwIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBUaG9tYXMgTXVucm8gPG11bnJvQGlwOS5vcmc+CkRhdGU6IFR1 ZSwgMyBKdWwgMjAxOCAwMDozMDo0OCArMTIwMApTdWJqZWN0OiBbUEFUQ0hdIFNwZWVkIHVwIHNl dHByb2N0aXRsZS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DEwMDY0NAotLS0gYS91c3IuYmlu L3RvcC9tYWNoaW5lLmMKKysrIGIvdXNyLmJpbi90b3AvbWFjaGluZS5jCkBAIC05NTAsNyArOTUw LDYgQEAgZm9ybWF0X25leHRfcHJvY2VzcyhzdHJ1Y3QgaGFuZGxlICogeGhhbmRsZSwgY2hhciAq KCpnZXRfdXNlcmlkKShpbnQpLCBpbnQgZmxhZ3MKIAkJfQogCX0gZWxzZSB7CiAJCWlmIChwcC0+ a2lfZmxhZyAmIFBfU1lTVEVNIHx8Ci0JCSAgICBwcC0+a2lfYXJncyA9PSBOVUxMIHx8CiAJCSAg ICAoYXJncyA9IGt2bV9nZXRhcmd2KGtkLCBwcCwgY21kbGVuKSkgPT0gTlVMTCB8fAogCQkgICAg ISgqYXJncykpIHsKIAkJCWlmIChwcy50aHJlYWQgJiYgcHAtPmtpX2ZsYWcgJiBQX0hBRFRIUkVB RFMgJiYKLS0gCjIuMTcuMAoK --00000000000023a918057003afda--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADLWmXWCj_WgYfQfzUL_aFLYYqezmbivzF=gKyk%2B6JqPcBvbXQ>