Zend Framework 2.0.0rc1, First Impressions

Zend Framework 2.0.0rc1 was released today. Unfortunately, I haven’t had time to keep up with ZF2 development since the early betas, so I had a read through Rob Allen’s ZF2 tutorial to see what has changed.

One interesting thing I saw was that the new Zend\Db\TableGateway uses the prototype pattern to instantiate result sets. Ralph Schindler explains the benefits of this approach in his blog post about constructors. TL;DR — using dynamic class instantiation (as was done in ZF1) is limiting because you have to make assumptions about the class’ constructor and dependencies. Using prototypes still allows you to choose the class used for result sets, but also provides flexibility around the class’ constructor and preserves any injected dependencies and configuration.

I also like how the new ServiceManager can use anonymous methods as factories, saving me from having to create dozens of tiny factory classes. And while I haven’t fully dug into the ViewModel stuff, from the little bits and pieces I’ve picked up from Twitter and coworkers it sounds like an elegant solution to the problem of passing context to the view renderer.

Put these improvements together with some of the stuff that has been there since the early betas such as events, improved routing, and better module support, and I’m really looking forward to using ZF2!

Configuring elasticsearch to Log Merges

elasticsearch periodically merges index segments. Merging can be expensive, and there are lots of parameters that can be tuned. But how do you know if merges are taking a long time?

As of version 0.16, elasticsearch supports logging merges, but the default logging.yml configuration file does not include the merge logging directive. Fortunately, adding it is very simple. Just add a index.merge: DEBUG line to the logger section. This will log all merges that take longer than 20 seconds to the main log file.

  # ...

  index.merge: DEBUG

If you want slow merges to be logged to their own file, duplicate the index_search_slow_log_file appender (call it index_merge_slow_log_file) and change the logger line to index.merge: DEBUG, index_merge_slow_log_file. To prevent merges from being logged to the main file, you also have to add a index.merge: false line to the additivity section.

  # ...

  index.merge: DEBUG, index_merge_slow_log_file

  # ...
  index.merge: false

  # ...

    type: dailyRollingFile
    file: ${path.logs}/${cluster.name}_index_merge_slowlog.log
    datePattern: "'.'yyyy-MM-dd"
      type: pattern
      conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"

Finally, if you want to log all merges, not just slow ones, change DEBUG to TRACE in the index.merge line.

Code Foo July 2012: Using Git

On Monday I will be presenting an introduction to Git to IGN’s Code Foo class of 2012. Some of the content makes some assumptions about IGN’s workflow, but most of it is generally applicable to anyone new to Git or looking for a refresher. The slides are done in reveal.js and the source is available on GitHub. I also have a copy of the presentation here on my blog.