HNHacker News
TopNewBestAskShowJobs

chanks

2,008 karma · joined June 22, 2010

github: chanks gmail: christopher dot m dot hanks
submissionscomments
chanks··on Ask HN: Is it acceptable to use a date as a primary key for a table in Postgres?
You can, but that won't protect you against invalid dates like an actual date type will.
chanks··on Why Rust?
I'm very curious how well this is working for you in practice, since I've been thinking about what it would look like to share a single Rust UI implementation across a webapp and native apps.
chanks··on Ruby 2.6.0-preview2 released with JIT
And Roda (https://github.com/jeremyevans/roda) beats Gin, if you include it: https://www.techempower.com/benchmarks/#section=data-r15&hw=...
chanks··on Ask HN: What are pros and cons of PostgreSQL and MySQL?
If you have a table that undergoes frequent updates and this is a concern of yours, look into setting a fillfactor on it. This will help Postgres keep writes in the same page, which means it doesn't need to touch indexes for non-indexed columns.

Edit: non-updated columns, I mean.

chanks··on My love-hate relationship with LuaJIT (2015)
Looking at your PR for it (https://github.com/LuaJIT/LuaJIT/pull/149) it sounds as if there are a few issues remaining, but I'm not enough of an expert to know how problematic they are in practice. Do you think that this feature is stable enough for production use?
chanks··on Ask HN: Who is hiring? (September 2016)
A small tree-based router for Ruby apps.

https://github.com/jeremyevans/roda

chanks··on Patching Rails Performance
That is, indeed, what Sequel does. You can query the database object directly (for example, `DB[:posts].where{comments_count > 5}.exclude(poster_name: "Bob").order(:comments_count.desc).limit(10).all`) and get back an array of hashes.

Sequel's model layer is also faster than ActiveRecord's, because much of the additional functionality that ActiveRecord piles onto all records (dirty tracking, single table inheritance, etc.) are available in Sequel via a plugin system. You can enable the plugins you want to use and not pay the overhead of all the others. You can even enable specific plugins for only the models where you'll actually want to use them.

It also has a lot less magic (no association proxies, unless you enable the plugin for them :)), ridiculously customizable (many more options for associations, custom eager loading logic, and so on), and has an implementation of its Postgres adapter written in C for performance.

Highly, highly recommended.

Edit: Oh, and an issue tracker that is almost always at zero, with a very fast response time. As someone who has contributed a patch to ActiveRecord, I can't tell you how nice that is.

chanks··on Postgres Job Queues and Failure by MVCC
Thank you!
chanks··on Postgres Job Queues and Failure by MVCC
(I'm the author of Que, the job queue discussed in the post most extensively)

This isn't terribly surprising to me, since I have an appreciation for what long-running transactions will do to a system, and I try to design systems to use transactions that are as short-lived as possible on OLTP systems. I realize that this should be explicitly mentioned in the docs, though, I'll fix that.

I'll also note that since the beginning Que has gone out of its way to use session-level locks, not transaction-level ones, to ensure that you can execute long-running jobs without the need to hold open a transaction while they work. So I don't see this so much as a flaw inherent in the library as something that people should keep in mind when they use it.

(It's also something that I expect will be much less of an issue in version 1.0, which is set up to use LISTEN/NOTIFY rather than a polling query to distribute most jobs. That said, 1.0 has been a relatively low priority for much of the last year, due to a lack of free time on my part and since I've never had any complaints with the locking performance before. I hope I'll be able to get it out in the next few months.)

chanks··on Don't Use an RDBMS for Messaging
My point is that the only way to wrap your jobs in the same transactions as the rest of your data is to have your job queue in your RDBMS. If you don't have that, you can't guarantee that they are consistent, that your backups have snapshots of each at the same time, etc.

Inconsistency between jobs and the rest of your data isn't a problem for many (or even most) use cases, but there are certainly times when you need it.

chanks··on Don't Use an RDBMS for Messaging
It can only be consistent with the rest of your data if the rest of your data is also in Redis.
chanks··on Don't Use an RDBMS for Messaging
The major benefit of putting your queue in your RDBMS, which isn't commonly brought up in these discussions, is that it lets you protect your jobs with the same ACID guarantees as the rest of your data. This is very valuable for some use cases.

I have a Postgres-based job queue that uses advisory locks to get around some of the drawbacks he mentions (job lock queries don't incur writes or block one another like SELECT FOR UPDATE would). Feedback is welcome: https://github.com/chanks/que

chanks··on Too Many Signals – Resque on Heroku
Hi, I'm the author of Que. It's true that you can't really completely solve the idempotence problem for jobs that write to external web services (unless those web services provide ways for you to check whether you've already performed a write - see the guide to writing reliable jobs in the /docs directory), but that's a limitation that'll apply to any queuing system. I'd definitely say that Que, being transactional and backed by Postgres' durability guarantees, does give you better tooling for writing reliable jobs than a Redis-backed queue would in general.

I'm happy to answer any questions you or anyone else might have.

chanks··on The Reykjavik Confessions
Frontline has an excellent episode on the Norfolk Four, a similar case that happened in Virginia: http://www.pbs.org/wgbh/pages/frontline/the-confessions/
chanks··on Costs of a PostgreSQL connection
You have some valid criticisms of the implementation, though pgsql-hackers has their reasons (http://www.postgresql.org/message-id/CAHyXU0ybwZZUbuQQVFQMK3...) for the way things are. Regardless, my point is that the situation is not so bad as "Every time that function is executed, it is re-parsed and re-planned."
chanks··on Costs of a PostgreSQL connection
PL/pgSQL function plans are cached. Functions written in other languages may not be, I don't know, but in my experience PL/pgSQL is the most widely used.

http://www.postgresql.org/docs/9.3/static/plpgsql-implementa...

chanks··on Que: A fast, concurrent job queue for Ruby and PostgreSQL
I'm really interested in suggestions or comments about Que - I'm trying to make it as durable as possible while retaining its speed.

I'm also looking for a steady job using Ruby, if anyone is hiring in Seattle. My email's in my profile.

Thanks!

chanks··on PostgreSQL 9.3 Beta 1 Released
What I would find helpful is some sort of operator to merge two JSON values. I use a JSON field to collect various statistics relating to a table's rows, and it'd be nice to not have to worry about overwriting old values. Something like:

json_merge('{"a":5,"b":7}', '{"b":6,"c":8}') -> '{"a":5,"b":6,"c":8}'

chanks··on Understanding Postgres Performance
One thing people don't mention that often with Postgres, but is worth some attention, is the Heap-Only Tuples (HOT) optimization that was added in 8.3. During an UPDATE, Postgres will try to fit the new version of the row on the same page as the old one - if it's able to do this, it means the indices don't have to be updated at all.

So if you're expecting a table to have a heavy UPDATE load it may be a good idea to lower its fillfactor from the default of 100 (for example, ALTER TABLE foo SET (fillfactor = 95);). This means that once a page is 95% full no new rows will be inserted into it, and the remaining 5% will be available for updated rows. HOT will also do "mini-vacuums" on individual pages as needed to free up space.

Of course, it's up to you to decide whether this tradeoff is worth increasing the effective size of your table by ~5%. But even tables with fillfactors at the default of 100 will get some benefit from HOT.

More info: https://github.com/postgres/postgres/blob/master/src/backend...

Edit to add: One caveat is that HOT won't work if you UPDATE a column that is indexed - then, of course, Postgres will have to touch the index.

chanks··on What 10gen nailed with MongoDB
I strongly recommend Sequel for Ruby:

http://sequel.rubyforge.org

It provides an ActiveModel-compliant interface, so it works fine with Rails. It also has a lot less magic (associations don't use proxy objects, for example) and has a lot of features that ActiveRecord is sorely missing (such as complete support for composite primary keys). I don't know what your other problems with ActiveRecord are, but Sequel is definitely worth a look. I'm very happy with it.

chanks··on Ask HN: How can I learn "advanced" data modelling for Rails?
That's nice to hear, I guess. I play with a lot of this stuff and still feel intermediate.
chanks··on Ask HN: How can I learn "advanced" data modelling for Rails?
I love Rails, but I strongly disagree with its philosophy of the DB as being just a dumb data store. Two things I would recommend.

One, the book Enterprise Rails. It's a few years old, so all the examples are from Rails 2, but the meat of it is about proper database design, including the stuff that Rails doesn't believe in (composite primary keys, foreign key constraints, check constraints, triggers). Chapter 4, about the importance of data integrity, was probably the single most useful thing I've read about web development in the past few years.

Most of it is on Google Books (although sadly, chunks of chapter 4 are missing): http://books.google.com/books?id=thTju-4duY4C&printsec=f...

Second, the best thing I did was replace ActiveRecord with Sequel. Sequel has built-in support for all of those things that ActiveRecord doesn't (I couldn't live without its composite primary key support), and is in general a much more robust library than ActiveRecord. It also supports more exotic SQL features like CTEs and CASE statements without forcing you to drop down to writing raw SQL (though you can certainly do that if you want).

It's not a necessary upgrade for everyone. If your app has fairly simple models and relationships, ActiveRecord will probably be just fine for you. But if you want to get better with SQL and get closer to your DB, I think Sequel is a much better choice.

More info on Sequel: http://sequel.rubyforge.org/

It also integrates very well with Postgres - there's a C extension for the Sequel postgres adapter (https://github.com/jeremyevans/sequel_pg) and support for adding common triggers in migrations, counter columns and whatnot (https://github.com/jeremyevans/sequel_postgresql_triggers). It also supports the more exotic datatypes - hstore, arrays, even the json and range types that are coming in PG 9.2.

chanks··on The Development of Sequel
I switched from ActiveRecord to Sequel about a year ago because I needed good support for composite primary keys, and I've never looked back. It's a phenomenal library, highly recommended.
chanks··on Heroku's new, free PostgreSQL 9.1 development database
Thanks, Matt. Can you share what the dev plan's row limit is? The blog post doesn't say.
chanks··on Heroku's new, free PostgreSQL 9.1 development database
It looks like Heroku's dropping the larger shared database offering ($15/month for 20 GB). That's... disconcerting. That means their cheapest production database now is the Ronin for $200 a month, but I have an app going into production soon that won't need anywhere near that much power.
chanks··on Show HN: Redis/ruby-based realtime event-tracking
I only took a quick glance through the source, but what's with the MongoDB dependency? Is there a chance that what you're using it for could be replaced with Redis? I already use Redis, but I'm hesitant to introduce yet another database into my stack unless it's absolutely necessary.
chanks··on What the hell is happening to rails?
Node.js isn't required. You can use any of the seven javascript runtimes that the ExecJS gem supports.

https://github.com/sstephenson/execjs

chanks··on Steve Wozniak Calls Paul Allen A Patent Troll
I should have submitted the original Register article. Sorry about that:

http://www.theregister.co.uk/2011/05/03/woz_talks_patents_an...

chanks··on (Ubuntu) 11.04, a leap forward
The sticking point for me with Unity was switching between multiple open windows. I typically have a dozen or so terminals and gedit and Chrome windows open across a half-dozen workspaces, but if I want to bring (let's say) a specific terminal on my current workspace to the foreground, I couldn't figure out a better way to do it than to open up Unity's display of all the many terminals I have running and try to pick out which one I mean.

I'm open to trying it again once it's had a bit more polish, but I'm sticking with Gnome classic for now.

chanks··on Modern divorce: Wiretapped teddy bears, $120,000 in fines
Those are called Safe Haven laws, and every state has them in some form or another.

http://en.wikipedia.org/wiki/Safe-haven_law

Page 1 of 2Next →