Thursday, June 11. 2009The Asynchronous Services Analogy
Today I had a chance to sit through a sneak preview of Theo Schlossnagle's new talk Scalable Internet Architectures, to be delivered next week at Velocity 2009 (Dev sessions are an underrated side benefit of working at OmniTI). As always Theo packs a lot of good information into his talks; I could probably do blog entries on half a dozen ideas I jotted down; but I wanted to highlight something that he mentioned with regards to scaling websites via asynchronous services.
Continue reading "The Asynchronous Services Analogy" Saturday, May 9. 2009IUCN Wildlife group needs development help
Passing this forward for a good cause, hopefully some of you can help out.
The African Elephant Specialist Group (with the Asian Elephant Specialist Group) is working on the redesign of the AED to become a multi-species database, the first version of which is the African and Asian Elephant Database. With funding from USFWS we are hiring a developer to undertake the project. I've put a copy of the TOR and Functional Specification on my site, but for more information, please contact: Note that the deadline for applications is May 11th, 2009. Saturday, November 8. 2008Beijing Perl Workshop 2008 SummarySaturday morning we got up a little later than we should have, so we skipped the breakfast at the hotel and headed out with subway directions in hand with hopes of grabbing food along the way and also not getting lost. This seemed likely to be more successful than trying to explain to a cabbie where we wanted to go, give a lack of Chinese language or address. Turns out this was a good idea. We grab some food from a street vendor that was cooked bread with a fried egg, some lettuce, and some mystery sauce, all of which was pretty tasty. The subway system proved pretty easy to navigate as well; consider it took me less time to find the conference building than it did to find my hotel in Toronto a couple years ago. (Maybe my subway skills have improved since moving out of Florida, where you can't actually dig underground without hitting sand and water?) Once we arrived at the conference, I signed in and got a nice little Perl China t-shirt. I say little because this has to be the smallest XXL shirt I have ever seen (it would make a Bangladeshi proud). We'll see if I can squeeze in, if not there might be a free shirt available soon... There were two rooms at the conference, with two talks running simultaneously. In the room where my talk was originally scheduled (I had been bumped to the afternoon to accommodate another speaker), there was a presentation on using Sequoia with EnterpriseDB. In Chinese. Hard to follow, but kind of interesting. Of the rest of the talks that followed (most with some reference to Perl and Postgres), I think my favorite was Jesse Vincent's "Everything But the Secret Sauce" talk, which I would seriously recommend any Perl programmer read through those slides and investigate the tools he's laid out. (Not sure where the specific slides are, but there are some versions available via the google). Toward the end of the day was my talk "The Essential postgresql.conf", which is a talk based on some work by Greg Smith and I, which we gave a version of at a BWPUG meeting a few months ago. The basic idea behind the talk is that while there are close to 200 parameters in the postgresql.conf, most people really only need to know about 20 of those to get proper performance. I also add in some up front information about how the postgresql.conf works, and some gotchas about managing your conf file. I think for the most part people were able to follow along, there was some nodding in the crowd as I went through the list which seemed like a good sign. One problem I had was that the microphone we had kept cutting out on me, which through me off a little (it had actually caused trouble all day, giving other static, or feedback, or just dieing), but I think folks were happy. I've put the slides on slideshare, which should be pretty handy for those who need to follow-up. After the conference, we went out for dinner with the other speakers and organizers for a Chinese Hot Pot dinner. The cab ride from the conference center to the restaurant was honestly quite frightening; our cab driver was not constraint by silly things like lanes; several times he used shoulders, on ramps, and sometimes even drove into opposing traffic to zing us on through the city. (I know Robert the 3rd is thinking "you have to earn your boost somehow"). It's good that we can laugh about it now, but in the future I think I will try to avoid cabs with racing grip steering wheels and drivers with formula 1 jackets one (honest!). Anyway, the dinner itself consists of a big table with a large, hot, pot in the middle, with boiling water into which you hold your food to cook it, community style. Interestingly, the place was apparently owned by Muslims (we found a nice plaque on the wall extolling the virtues of Allah), so I think the meat consisted of beef and lamb, but no pork. The food was good, the company was good, and the conversation good as well (guess what, the folks in Beijing can't find good perl programmers either). We also talked a bit about the PostgreSQL community within China, which is growing well, though the language barrier has prevented a lot of interaction with the larger community. There is interest to forming some regional user groups, but right now they seem pretty happy coordinating on a more national level, and also working with the strong ties they have in the Perl community. We should definitely expect to see more conferences and other activities going forward though. All said it was a nice conference and I'm glad to have had the opportunity to come and meet a bunch of enthusiastic postgres folks, and hope to work with them more in the future. As we have focused mostly on open source and tech so far, we hope to spend the next couple of days sight seeing, which I'm sure will be awesome as well. We have had to deal with some dodgey internet at times, but expect photos to go up on line sometime soon. Thanks again to everyone involved for an awesome event. Tuesday, November 20. 2007tracking plperl shared variables
If you use as much Perl and PostgreSQL as we do at OmniTI, you're bound to start building complex software solutions using [http://www.postgresql.org/docs/current/interactive/plperl.html plperl]. One of our latest projects (internally known as abyss) involves long term storage and archiving of email inside of PostgreSQL. That part isn't interesting. The interesting part is how we make use of a bunch of custom perl modules we wrote, inside of plperl, to parse, digest, and dissect the information inside of those emails, transforming the data into something that can be analyzed more thoroughly by normal database tools; essentially giving structure to the semi-structured data inside of email.
One of the parts that makes plperl so handy is it's ability to use shared variables, to pass data from one function to another inside of a backend session. Using this technique, you can really start to do some interesting things, but it does present one problem when your trying to debug, specifically how to see the values that are getting passed around in a session. Luckily the solution is a lot simpler than you would think. CREATE OR REPLACE FUNCTION dump_shared()As you can see, we use the perl "[http://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm Dumper]" module to dump out all of the shared variables you might be looking at, in a fairly oragnized manner. Woohoo! Incidentally, we're hiring Perl developers to work on things like this, as well as some other big projects using Perl and PostgreSQL, among other stuff, so if you think you have what it takes, check out our [http://www.omniti.com/people/jobs#webdev job posting] and send in that resume! Thursday, September 6. 2007Out parameters in plperl
One evening last week, I got some suspcious IM's from Theo, asking me questions like what is the syntax of an out parameter? (out param datatype), and what return type needs to be used wrt out params (generally setof record). A few minutes later he asked me how one returns the rows from such a function in plperl, to which I sheepishly replied "I think you have to build an array and then return each row that way", which I thought was close but honestly was more of an educated guess.
A guess because I couldn't remember anyone ever using out params in plperl. And that got me thinking that, maybe plperl didn't support out params? A quick google search turned up an article on plperl and postgresql 8.1 by Andrew Dunstan, who noted that IN/OUT params for plperl were still on the TODO list. So I did a quick scan of the 8.2 release notes, and found nothing there about IN/OUT support added to pl/perl. One last check, I popped on to #postgresql, and located David Fetter, a noted plperl advocate, and asked him if PostgreSQL supported OUT params for plperl. His reply? "If it does, it's undocumented". Drat. As I was on my way home anyway, I swung by Theo's office and told him that I wasn't sure if plperl actually supported OUT parameters, to which he replied "Oh no problem, I already have it working". Never doubt what a person can accomplish when they don't know they can't do something. So, for all of that, ISTM a good idea to post a simple example of how it actually works, so that others trying to figure out the syntax might have something to look at. This example is about as dead simple as it gets, we just iterate through some numbers, and spit out two columns for each item. CREATE OR REPLACE FUNCTION setof_plperl(out number integer, out oddoreven text)There you go! Hopefully that basic example will be enough to get you started. On a side note, I spoke with David after this "discovery" and he said that he has investigated things and found a couple ways to do this, and has promised to submit a doc patch for 8.3, so hopefully this will get even easier. Thursday, June 15. 2006OnLamp Article Published
Just a quick heads up that I've had a new article published at OnLamp.com. The article shows how to [http://www.onlamp.com/pub/a/onlamp/2006/06/15/aim-answerbot.html build your own question and answer bot] for AIM using a bit of perl and some postgresql. The best part is the cool little image they made for it [[image /xzilla/templates/default/img/emoticons/smile.png alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /]]
[[image /xzilla/uploads/onlamp_answerbot.gif border="1" alt="Cute Little AnswerBot. Image Copyright 2006 O'Reilly Inc. Used without permission"]] Wednesday, June 14. 2006delayed returns with plperl
The other day I ran into a roadblock in a function I wanted to refactor. What I needed to do was execute a query, followed by another query that was based on the first queries output, and then return the results of the first query based upon the outcome of the second query. A little convoluted sure, but sometimes that's what you need. In any case it turns out theres really no way to do this in plpgsql; looping through a stored recordset is pretty much out of the question without using temp tables. I also thought about using pltcl, but unfortunatly it doesn't support SRF's, so that was out too. The following is my rough "proof of concept" function written in plperl, which seemed the language best suited to getting this done. (I'd be interested in other languages though)
CREATE OR REPLACE FUNCTION delayed_return (integer) RETURNS setof integer LANGUAGE plperl AS $$ my $foo = $_[0]; my $bar = $foo/2; my $sql = "select from generate_series(1,$foo);"; my $sth = spi_query($sql); my @sb; $sql2 = "select from generate_series (3,$bar) WHERE generate_series IN (0"; while (defined ($row = spi_fetchrow($sth))) { elog(NOTICE, "SB1-row_number::$row->{generate_series}"); @sb = (@sb, $row->{generate_series}); if ($row->{generate_series}%2 == 0){ $sql2 = $sql2 . ",$row->{generate_series}"; }; }; $sql2 = $sql2 . ');'; elog(NOTICE,"$sql2"); my $sth2 = spi_query($sql2); my @ex; while (defined ($row2 = spi_fetchrow($sth2))) { elog(NOTICE, "EX-row_number::$row2->{generate_series}"); @ex = (@ex,$row2->{generate_series}); }; foreach $b (@sb) { if (grep {$_ eq $b } @ex ) { elog(NOTICE, "SB2-row_number::$b"); return_next($b); }; }; return; $$; davinci=# SELECT FROM delayed_return(18); NOTICE: SB1-row_number::1 NOTICE: SB1-row_number::2 NOTICE: SB1-row_number::3 NOTICE: SB1-row_number::4 NOTICE: SB1-row_number::5 NOTICE: SB1-row_number::6 NOTICE: SB1-row_number::7 NOTICE: SB1-row_number::8 NOTICE: SB1-row_number::9 NOTICE: SB1-row_number::10 NOTICE: SB1-row_number::11 NOTICE: SB1-row_number::12 NOTICE: SB1-row_number::13 NOTICE: SB1-row_number::14 NOTICE: SB1-row_number::15 NOTICE: SB1-row_number::16 NOTICE: SB1-row_number::17 NOTICE: SB1-row_number::18 NOTICE: select from generate_series (3,9) WHERE generate_series IN (0,2,4,6,8,10,12,14,16,18); NOTICE: EX-row_number::4 NOTICE: EX-row_number::6 NOTICE: EX-row_number::8 NOTICE: SB2-row_number::4 NOTICE: SB2-row_number::6 NOTICE: SB2-row_number::8 delayed_return ---------------- 4 6 8 (3 rows)
(Page 1 of 1, totaling 7 entries)
|
QuicksearchThis is the weblog of Robert Treat. I lead the Database Operations Group at OmniTI, where we work on some of todays largest database challenges. bio | writings Hire me! Need help with your database? We are available for large scale or short term engagements. Hire you! If you have experience with Postgres, MySQL, or Oracle, we are looking for people to join our team. Upcoming Events
PG East 2010 March 25th - 28th At Philadelphia, Pennsylvania PGCon 2010 May 18th - 21st At Ottawa, Canada Syndicate This BlogBlog Administration |

You were saying?
Tue, 09.03.2010 19:39
I'm way too lazy to type it al l, and it's not on the web, so far as I know, but here's the bottom of pg. 485: S [...]
Tue, 09.03.2010 19:31
Jeff: >> That might be an inc idental benefit. Robert: > > but the freebie that comes along for the ride is, l [...]
Tue, 09.03.2010 16:06
"The point of the relational m odel... is to slay the scalabi lity dragon by avoiding the by te bloat in the first pl [...]