For most books, but technical non-fiction in particular, the payout isn't nearly worth enough for the effort.
And by "most" there I mean "all". Yes, there are exceptions, but those exceptions prove the rule.
I've written 2 technical books, for incredibly niche audiences, where the total number of potential buyers is numbered in the low thousands.
I self published as a PDF. and charge $200 a copy, of which I keep $200. It's -marginally- worth it. But the hourly rate is much lower than my day job.
The marketing benefit (as it affects my actual business in the same field) is likely real, but hard to measure. Still, having "written the book" opens doors, and brings credibility.