Once a program has been debugged and works properly, it might be time to start optimizing it. A common way of doing this is a method called profiling – watching a program execute and counting the amount of computing time each step in the program takes. This is all well and good for most programs, but gets complicated when processes execute on more than one core. A profiler may count time spent waiting in a program for a process in another core to finish, giving meaningless results. To solve this problem, a method called casual profiling was developed.
In casual profiling, markers are placed in the code and the profiler can measure how fast the program gets to these markers. Since multiple cores are involved, and the profiler can’t speed up the rest of the program, it actually slows everything else down and measures the markers in order to simulate an increase in speed. [Daniel Morsig] took this idea and implemented it in Go, with an example used to demonstrate its effectiveness speeding up a single process by 95%, resulting in a 22% increase in the entire program. Using a regular profiler only counted a 3% increase, which was not as informative as the casual profiler’s 22% measurement.
We got this tip from [Greg Kennedy] who notes that he hasn’t seen much use of casual profiling outside of the academic world, but we agree that there is likely some usefulness to this method of keeping track of a multi-threaded program’s efficiency. If you know of any other ways of solving this problem, or have seen causal profiling in use in the wild, let us know in the comments below.
Header image: Alan Lorenzo [CC BY-SA 3.0].
The king of machine tools is the lathe, and if the king has a heart, it’s probably the leadscrew. That’s the bit that allows threading operations, arguably the most important job a lathe can tackle. It’s a simple concept, really – the leadscrew is mechanically linked through gears to the spindle so that the cutting tool moves along the long axis of the workpiece as it rotates, allowing it to cut threads of the desired pitch.
But what’s simple in concept can be complicated in reality. As [Clough42] points out, most lathes couple the lead screw to the spindle drive through a complex series of gears that need to be swapped in and out to accommodate different thread pitches, and makes going from imperial to metric a whole ball of wax by itself. So he set about building an electronic leadscrew for his lathe. The idea is to forgo the gear train and drive the leadscrew directly with a high-quality stepper motor. That sounds easy enough, but bear in mind that the translation of the tool needs to be perfectly synchronized with the rotation of the spindle to make threading possible. That will be accomplished with an industrial-grade quadrature encoder coupled to the spindle, which will tell software running on a TI LaunchPad how fast to turn the stepper – and in which direction, to control thread handedness. The video below has some great detail on real-time operating systems on microcontrollers as well as tests on all the hardware to be used.
This is only a proof of concept at this point, but we’re looking forward to the rest of this series. In the meantime, [Quinn Dunki]’s excellent series on choosing a lathe should keep you going.
Continue reading “Benchtop Lathe Gets An Electronic Leadscrew Makeover”
Getting into the weeds of operating systems is daunting work. Especially when the operating system involved is a fully featured modern PC operating system with millions of lines of code all working together to integrate hardware and software seamlessly. One such operating system “weed” is figuring out how to handle simultaneous tasks when the processor can only really handle one thing at time. For that, you’ll be looking at the difference between spinlocks and mutexes.
Both of these are methods of making sure that the processor completes a task sufficiently before moving on to the next task. Modern computers are so fast (even ignoring multiple cores) that it seems as if they are doing many things at once. In order to maintain this illusion, tasks need ways of locking the processor to that specific task for a certain amount of time. Of course the queue for performing the next task can get complicated as there are often many tasks waiting to use processor time. Spinlocks are a simple way of holding the processor and mutexes are a slightly more complicated way, but which one is the most efficient use of system resources isn’t that straightforward.
If you’ve ever been interested in operating system details, this one goes deep into the intricacies of features most of us have never even considered the existence of. It’s definitely worth a read, though, and is very well written by someone who is clearly an expert. If you want an operating system challenge, you can build your own operating system as well.
The ability to execute code in parallel is crucial in a wide variety of scenarios. Concurrent programming is a key asset for web servers, producer/consumer models, batch number-crunching and pretty much any time an application is bottlenecked by a resource.
It’s sadly the case that writing quality concurrent code can be a real headache, but this article aims to demonstrate how easy it is to get started writing threaded programs in Python. Due to the large number of modules available in the standard library which are there to help out with this kind of thing, it’s often the case that simple concurrent tasks are surprisingly quick to implement.
We’ll walk through the difference between threads and processes in a Python context, before reviewing some of the different approaches you can take and what they’re best suited for.
Continue reading “Thread Carefully: An Introduction To Concurrent Python”
It’s the suburbanista’s weekend nightmare: you’re almost done with the weekly chores, taking the last few passes with the lawn mower, when you hear a pop and bang. The cylinder head on your mower just blew, and you’re out of commission. Or are you? You’ve got a 3D printer – couldn’t it save the day?
If this bench test of plastic cylinder heads is any indication, it’s possible – just as long as you’ve only got 40 seconds of mowing left to do. [Project Farm] has been running all sorts of tests on different materials as field-expedient cylinder heads for small gasoline engines, using everything from JB Weld epoxy to a slab of walnut. For this test, two chunky heads were printed, one from ABS, of the thermochromic variety apparently, the other in PLA. The test went pretty much as expected for something made of thermoplastic exposed to burning gasoline at high pressure, although ABS was the clear winner with two 40-second runs. The PLA only lasted half as long before the spark plug threads melted and the plug blew out. A gasket printed from flexible filament was also tested, with predictably awful results.
As bad as all this was, it still shows that 3D-printed parts are surprisingly tough. Each part was able to perform decently under a compression test, showing that they can stand up to pressure as long as there’s no heat. If nothing else, it was a learning experience. And as an aside, the cylinder heads were printed by [Terry] from the RedNeckCanadians YouTube channel. That video is worth a watch, if just for a few tips on making a 3D-printed copy of an object. Continue reading “Results Of 3D-Printed Cylinder Head Testing Fail To Surprise”
Wood can be the material of choice for many kinds of projects, but it often falls out of the running in favor of metal or plastic if it needs to take a threaded fastener. But with a little ingenuity you can make your own wood taps and cut threads that will perform great.
Making wood do things that wood isn’t supposed to do is [Matthias Wandel]’s thing. Hackers the world over know and use his wood gears designer to lay out gears for all kinds of projects from musical marble machines to a wooden Antikythera mechanism. Woodworkers have been threading wood for centuries , so making wood take a decent thread isn’t exactly something new. But doing it on the cheap and making the threads clean and solid has always been tricky. The video after the break shows [Matthias]’ method of cutting a tap out of an ordinary threaded rod or even off-the-shelf lag screws. He uses a simple jig to hold the blank so that flutes can be cut with an angle grinder. The taps work well in the materials he tested, and a little informal stress testing at the end of the video shows promise for long service life of the threads.
Wood threads aren’t suitable for every project, but knowing that you can do it might just open the path to a quick, easy build. This is a great tip to keep in mind.
Continue reading “Simple Shop-made Taps For Threading Wood”