Show HN: StackImpact – Python Production Profiler: CPU, Memory, Exceptions
github.com
github.com
Is there something like this (show memory use and call times for a Python process) that just runs on my computer to help me profile a long-running Python process?
pyrasite (http://pyrasite.com/) will let you inject code into a process. This can be used to add monitoring of private internal state etc (if you have no other options).
If you want to have locally hosted graphs then grafana and influx are my current tools of choice.
It is going to be more work than swiping a credit card, but not a crazy amount.
cinnamon-screensaver would take multiple seconds to lock the screen even after I'd stopped profiling and exited the interpreter I'd injected, and I wound up restarting it so I could lock my screen quickly again.
I don't know why this happened, but it's enough to make me think twice, and I'm definitely going to double-check my process is still performing as I hope after injecting it with pyrasite in the future.
Sysdig is available though. It even got userspace tracers recently (including Python). Alternatively there's "perf" if you want just the kernel side.
For Python3: https://github.com/rixx/lptrace/tree/python3
I have a question for hacker news. Does Python still have a lot of momentum in this area? I love Python and use it whenever I can, but I find these days that most web frameworks assume right off the bat that you are using Node. The frontend landscape is so heavily tilted towards using js (and tools such as npm, etc) on the backend that fitting it into a Python flow is difficult, especially for beginners. In addition, we have the relatively fresh trend of using isomorphic code on both Node and the client. It seems like my beloved Python is being pushed to the background. Is there any truth to this? I would very much like to keep investing my energy into what I know, but if it is wasted effort, I will stop.
While I've used Node, and I think it has its place in certain kinds of application, I would never pick it for the main backend language. Adding a chat service to an existing larger codebase, maybe, but JS isn't particularly well suited to larger applications (yet, it's improving) and the frameworks are still less mature than things like Django and Rails.
I'd say python is slowly growing if anything. The javascript world is probably growing faster, but then you are competing in a much bigger field.
I am personally skeptical of these trends, but my skepticism doesn't change the shift of the industry. My advice would be to get some Node and React experience under your belt so that you can at least discuss it intelligently, and it shouldn't be too much of an impediment moving forward.
Python is in a tough spot for growth, IMO. The new generation of languages have internalized much of what made Python great, while leaving behind a lot of the inadequacies and cruft attached to CPython.
Like you, I will always have a soft spot for Python, but it's getting increasingly difficult to continue to see it as the default choice for new projects (outside of a few specific niches).
Do you think React is something to learn together with Node or would you recommend just getting to know React on its own?
React and Node are not really related other than they're both JavaScript-based, so the skills aren't really co-dependent. Node is used to execute JavaScript locally (in build tools like Webpack, for example), but beyond a small amount of local scripting for builds, they don't really touch (afaik; I have not yet completed a major project with either of them, just used them here and there).
Render services [1], Sidecar processes [2], not-doing-universal-rendering, or just running a simple universal nodejs server with an entirely separate API backend.
[1]: https://github.com/airbnb/hypernova [2]: https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-...
Integration is not typically that difficult. It takes a day or two of sitting down with docs and intentional effort, sure.
Worrying about wasted effort is silly though. The amount of choice these days is crazy, and web development lately is mostly hype-driven, though it doesn't really need to be. We end up solving the same problems over and over again with a slightly different set of technologies (which has it's good notes and it's bad notes).
For many companies the backend is several orders of magnitude larger than the frontend (hundreds of separate backend services/daemons/etc in any variety of languages), so optimizing the whole stack for the sake of the frontend would be nuts
I have no experience with server side rendering though but I can't imagine any problems with that either.
Would it be possible to host this on premise?
Sentry seems to do quite well with a business model where customers are free to host it on premise. That might be worth a consideration.
I for one am interested but for me to become a customer I would first need to be able to trail it on my staging environment. Providing a docker container that I can host on premise would go a long way towards being able to do that.
Now, I am surprised I didn't push it forward.
I've been thinking about building my own using Prometheus as collector/visualiser. Time hasn't been on my side, but eventually...
I am particularly interested in who best supports .NET on Windows.
Do you have the methodology and data that you used to obtain this figure? Because to be honest I'm quite dubious, especially for an app which is CPU bound.
The feature set between this and New Relic is quite different. To oversimplify, New Relic works at the python library level, and StackImpact works at the python interpreter level. The functionality is potentially complementary.
Would this help? Any other suggestions?
Edit: Exact same code is hugely faster on a webserver in production. And its not the Vbox specs, i gave it lots of RAM and 4 CPUs.
If you're on Mac or Linux, you can massively reduce the amount of filesystem overhead by using Docker (or Docker Compose) for local testing, since on Linux it'll get direct access to the FS and on Mac it will use the special osxfs driver. You can also try using nfs to mount your drives instead of vbox shared folders if you want a quick gain, but it will make hot reloading even less reliable.
You may also want to be sure your settings are really the same. Does DEBUG=0 change anything? What cache backend are you using? Etc.
Finally, if none of the above helps you can try a move of desperation: try to get the app working on your native OS with no container or VM layer.
There are a number of toolbar bugs at https://github.com/jazzband/django-debug-toolbar/issues/943 involving keywords "slow" and "hang", not sure which it was.
But the meta-issue is, the profiling tools I used were not super helpful in discovering what the issue was.
I did solve this by removing django debug toolbar though trial and error (and still not sure why it was doing that), but I never found a tool which would discover that problem.
> Time (blocking call) profiler supports threads and gevent.
(from https://stackimpact.com/docs/#getting-started-with-python-pr...)
[1] https://www.youtube.com/watch?v=NdObDUbLjdg [2] https://www.python.org/dev/peps/pep-0523/
Deterministic profiling monitors every function call to track timing information. This is very precise but adds significant overhead. Statistical profiling samples the call stack periodically to see what functions are running. This is less precise but has less overhead. The overhead varies depending on how frequently you sample and what the sampling mechanism is.
StackImpact is a statistical profiler. At a quick glance it looks like they're using threading.Timer to periodically run their profiling functions.