Nothing at all surprising. But what the hell is this Nette thing everyone in the Chezh Republic is using??
Month: March 2015
Working with Beanstalk Queues
Queueing is a natural part of modern web applications. Without it, you will end up with a poor user experience due to unnecessary execution blocking leading to inadequate response times. In Laravel (which everyone is using, of course), one of the easiest providers to get going with queues is beanstalkd. You can set it up in 15 seconds on any linux distro – and away you go without any configuration necessary. However when you need to debug and investigate, it isn’t really clear how to proceed. As such, I wanted to quickly go over some tools that I’ve discovered which are very helpful.
CLI based tube inspection
If all you have is a CLI, and you want a hassle-free way to check your tubes, I highly recommend beanstool. With no setup necessary, it will quickly give you all the info you need.
Web based tube inspector
If you need a GUI and/or more detail, then beanstalk console has you covered. It’s a very simple and lightweight PHP application which will give you plenty of info, and allow you to quickly and efficiently go through your tubes if they are clogged with several jobs.
Clear a queue in Laravel
This is perhaps the single most useful one. The scenario is that you have hundreds or thousands of faulty jobs stuck in your queue, and you want to quickly clear all of them. Amazingly, there is no trivial out-of-the-box way to do that, so I’ve come up with the following Laravel Command to get that job done.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<?php namespace Project\Commands; use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputArgument; class ClearQueue extends Command { /** * The console command name. * * @var string */ protected $name = 'queue:clear'; /** * The console command description. * * @var string */ protected $description = 'Clear a Beanstalkd queue, by deleting all pending jobs.'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Defines the arguments. * * @return array */ public function getArguments() { return array( array('queue', InputArgument::OPTIONAL, 'The name of the queue to clear.'), ); } /** * Execute the console command. * * @return void */ public function fire() { $queue = ($this->argument('queue')) ? $this->argument('queue') : \Config::get('queue.connections.beanstalkd.queue'); $this->info(sprintf('Clearing queue: %s', $queue)); $pheanstalk = \Queue::getPheanstalk(); $pheanstalk->useTube($queue); $pheanstalk->watch($queue); while ($job = $pheanstalk->reserve(0)) { $pheanstalk->delete($job); } $this->info('...cleared.'); } } |
PHP Conference 2015
I’ve just attended the PHP Australia conference on the 12th and 13th of March. This was my first ever actual full blown conference in anything, and I have to say, it was pretty amazing. Apart from the creators of PHP and MySQL (now working on MariaDB of course), there was an awesome list of speakers and lots of great food. This is probably a good time to give Seb kudos for managing to organise such a packed event.
I’ve been compiling notes for work (props to 4mation for paying for my ticket), and so far I have almost 4 pages, which is pretty cool. There are so many takeaways, it seems pointless to even try to get into them, however I will say that talking to Rasmus and Monty was by far the highlight of the two days. Lesser so, it was also interesting to discuss technologies in use with people from all around Australia, what their stack is, and how they go about development.
The Value of Learning
Today at work, at our Monday general meeting, I gave a brief speech about my take on our value of Learning… so why not also share it with the world?
I believe that no other industry other than ours is so fast paced in terms of the technology needed to accomplish our jobs. Something which might be relevant one year, will be shunned and largely disused the next. Every week there is a new acronym for a new developer tool, every month there is an update to a framework we use. Development paradigms are always changing.
In short, if we are to excell above our competitors, we must truly embrace all facets of the learning process. We quite simply don’t have the right to call ourselves professionals without fully exhausting all the avenues we have at our disposal to learn new things.
These will come in the form of online seminars, meetup groups and conferences, discussing projects with colleages, work outside of work, always helping people – on stack overflow, forums and IRC, hours and hours of reading online documentation at midnight, and a good old fashioned book or two.
The media and news programs always report that our profession has benefits and culture which is the envy of every worker on the planet. I for one believe we should work hard to earn this place of ours in the world.
Remote control your phone through ADB
This weekend I’ve dropped my phone once too many times, and the screen controller died. The man at the phone repair shop said the motherboard is broken, and nothing can be done, and there’s no way any data can be retrieved. The touchscreen is non responsive, hence there’s no way to unlock my phone, even if the screen is replaced.
Very very luckily, I still somehow had my phone’s ADB key stored on my computer, and a colleague of mine told me about a program which without me having to do anything on the phone at all, can use that key to remote control my phone from the computer, and emulate the touch screen. You can find more details about that here, but long story short, the existence of that program, and me having hooked up my phone to adb to play around with it once before totally saved me from losing 2 years of important personal data from my phone.
I’ve never been so relieved.
The Laravangular Stack (with Postgres)
Let’s start March with some tech talk.
I’m going to be talking about technologies that we use to develop new web applications from scratch. For normal applications (ie. the 98% thereof which contrary to what hipster devs on your team believe, do not have a legitimate use case for mongo), this is the technology stack which I feel is far superior to any other choice. I call it the Laravangular Stack.
To begin with, all modern web applications must be designed API first with a separate backend and frontend. The reasons for this are obvious;
- Separation of concerns
- Easier automated testing
- Code once for multiple consumers (ie. web, mobile, device, API for 3rd parties, etc)
- Performance
- Easier to upgrade components
- Easier to debug
- Easier to divide dev workload
- Your application architecture isn’t a sack of shit
- Ability to have a rich, interactive frontend (and stop pretending that jQuery can accomplish this)
The question then becomes, what specific technologies do we use for such an application? In my view these answers are obvious.
Laravel has you covered on the backend
Laravel is the best thing that’s ever happened to web programming period. The most popular framework has you totally covered for API-first projects, and will deliver more features with more simplicity than anything else in existence – while the community is hard at work churning out thousands of packages for you to leverage in your project. It’s an obvious choice.
Angular for a superb user experience
Angular, at least for now, is the only proper actual front-end framework. Yes, it’s far from perfect, and some have even gone so far as to call it a tech demo…. however until Angular 2 comes out, there isn’t anything which can compete with it because everything else is essentially a bit of wet lettuce. Frontend JS frameworks are a very recent invention, and it’s an interesting new space – but the sooner you come to terms with the fact that Angular at the moment simply shits on everything else out there, the sooner you can begin to create world-beating applications.
PostgreSQL for RDMS
Many people still use MariaDB (or god forbid MySQL), however I’ve felt for a long time that it is rather inferior to PostgreSQL. A project I’m working on now has cemented my view, with 2 rather sharp examples.
Our first problem stemmed from having a very high write workload for one logging aspect in our system. The use case involves a very large number of external devices writing logs to our system every few minutes. In our testing, InnoDB is a severe bottleneck for write-heavy workloads. I have read up on this, and the tl;dr is that there is no way to fix it – it’s just the way it’s designed. That rather sucks.
The second problem are UUIDs. UUIDs are pretty much the gold standard now, especially when it comes to anything API. How do you store them in a database though? Well, in the case of MariaDB, there is no perfect solution. If you want optimal performance, you can choose to store it as a binary 16 – and say goodbye to ever being able to manually read or write any UUID. Alternatively you could store it as varchar 36 (or 32 without the dashes), but take a non-trivial performance hit.
PostgreSQL on the other hand has had a naitive UUID field for a while now, which is internally stored as if it were binary, but behaves like a char. Likewise, it has no performance problems with write-heavy workloads. Perfect!
Of course when you come down to the bottom of it, there are many more differences between MariaDB and PostgreSQL – and you’ll likely find that PostgreSQL can do everything MariaDB does, but also more. It just so happens that PostgreSQL is always first to the party with any number of features that it’s had first in the last decade or more, including being an actual database system with full ACID compliance. It’s only pitfall if any is the lack of tools (relatively speaking) compared to MariaDB. If you can get past that barrier however, I would definitely recommend it.
Everything else is irrelevant
Whether you use Apache or Nginx, they both proxy pass PHP requests straight to php-fpm in all modern configurations, and let’s face it, nobody serves static assets anymore – it all comes from CDNs. Whatever other technologies used, wherever you are hosted – it’s less relevant than getting the fundamentals right.