Due to Netflix outage this week I was thinking about getting their Vudu appliance for instant on-demand streaming to a TV set. But then, it seems that those appliances are just interim products, till we move to something better, sort of like CD-ROMs.

The better in this case is wireless HDMI. Since Netflix already supports streaming part of their catalogue to your PC, it’s just the matter of time till you can get that stream in high-def, and then plug in a wireless HDMI adapter to stream it directly to the television, bypassing a settop box entirely.

A limited selection of wireless HDMI products on the market is pretty pricey nowadays compared to a box from Vudu sold through Netflix. A set of extenders from Gefen is currently $700. Belkin Flyware HDMI transmitter is also $700. Hopefully the pricing would follow the DVD player timeline close enough.

Posted in Entertainment, Gadgets, General, Money, Technology, Wireless at August 15th, 2008. No Comments.

Anthony Dovgal reported on adding open source SQL full-text search engine sphinx to PECL. The documentation is available on the PHP site, the engine is available upon including sphinxapi.php in your application. You know the usual InnoDB vs. the MyISAM trade-offs, where the former is faster, but the latter has the full-text search? Sphinx is a free open-source full-text search engine that works with many RDMBS, and now is pretty easy to incorporate into PHP. A simple example of calling Sphinx is available here:

$s = new SphinxClient;
$s->setServer("localhost", 6712);
$s->setMatchMode(SPH_MATCH_ANY);
$s->setMaxQueryTime(3);
$result = $s->query("test");

Posted in New software releases, PHP, Programming at July 31st, 2008. No Comments.

John Coggeshall, CTO of Automotive Computer Services, and author of Zend PHP Certification Practice Book and PHP5 Unleashed, gave a talk at OSCON 2008 on top 10 scalability mistakes. I wasn’t there, but he posted the slides for everybody to follow. Here’re some lessons learned.

  1. Define the scalability goals for your application. If you don’t know how many requests you’re shooting for, you don’t know whether you’ve built something that works, and how long it’s going to last you.
  2. Measure everything. CPU usage, memory usage, disk I/O, network I/O, requests per second, with the last one being the most important. If you don’t know the baseline, you don’t know whether you’ve improved.
  3. Design your database with scalability in mind. Assume you’ll have to implement replication.
  4. Do not rely on NFS for code sharing on a server farm. It’s slow and it’s got locking issues. While the idea of keeping one copy of code, and letting the rest of the servers load them via NFS might seem very convenient, it doesn’t work in practice. Stick to some tried practices like rsync. Keep the code local to the machine serving it, even if it means a longer push process.
  5. Play around with I/O buffers. If you’ve got tons of memory, play with TCP buffer size - your defaults are likely to be set conservatively. See your tax dollars at work and use this Linux TCP Tuning guide. If your site is written in PHP, use output buffering functions.
  6. Use Ram Disks for any data that’s disposable. But you do need a lot of available RAM lying around.
  7. Optimize bandwidth consumption by enabling compression via mod_deflate, setting zlib.put_compression value to true for PHP sites, or Tidy content reduction for PHP+Tidy sites.
  8. Confugure PHP for speed. Turn off the following: register_globals, auto_globals_jit, magic_quotes_gpc, expose_php, register_argc_argv, always_populate_raw_post_data, session.use_trans_sid, session.auto_start. Set session.gc_divisor to 10,000, output_buffering to 4096, in John’s example.
  9. Do not use blocking I/O, such as reading another remote page via curl. Make all the calls non-blocking, otherwise the wait is something you can’t really optimize against. Rely on background scripts to pull down the data necessary for processing the request.
  10. Don’t underestimate caching. If a page is cached for 5 minutes, and you get even 10 requests per second for a given page, that’s 3,000 requests your database doesn’t have to process.
  11. Consider PHP op-code cache. This will be available to you off-the-shelf with PHP6.
  12. For content sites consider taking static stuff out of dynamic context. Let’s say you run a content site, where the article content remains the same, while the rest of the page is personalized for each user, as it has My Articles section, and so on. Instead of getting everything dynamically from the DB, consider generating yet another PHP file on the first request, where the article text would be stored in raw HTML, and dynamic data pulled for logged-in users. This way the generated PHP file will only pull out the data that’s actually dynamic.
  13. Pay great attention to database design. Learn indexes and know how to use them properly. InnoDB outperforms MyISAM in almost all contexts, but doesn’t do full-text searching. (Use sphinx if your search needs get out of control.)
  14. Design PHP applications in an abstract way, so that the app never needs to know the IP address of the MySQL server. Something like ‘mysql-writer-db’, and ‘mysql-reader-db’ will be perfectly ok for a PHP app.
  15. Run external scripts monitoring the system health. Have the scripts change the HOSTS if things get out of control.
  16. Do not do database connectivity decision-making in PHP. Don’t spend time doing fallbacks if your primary DB is down. Consider running MySQL Proxy for simplifying DB connectivity issues.
  17. For super-fast reads consider SQLite.  But don’t forget that it’s horrible with writes.
  18. Use Keepalive properly. Use it when both static and dynamic files are served off the same server, and you can control the timeouts, so that a bunch of Keep-alive requests don’t overwhelm your system. John’s rule? No Keep-alive request should last more than 10 seconds.
  19. Monitor via familiar Linux commands. Such as iostat and vmstat. The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks. vmstat  reports  information about processes, memory, paging, block IO, traps, and cpu activity.
  20. Make sure you’re logging relevant information right away. Otherwise debugging issues is going to get tricky.
  21. Prioritize your optimizations. Optimization by 50% of the code that runs on 2% of the pages will result in 1% total improvement. Optimizing 10% of the code that runs on 80% of the pages results in 8% overall improvement.
  22. Use profilers. They draw pretty graphs, they’re generally easy to use.
  23. Keep track of your system performance. Keep a spreadsheet of some common stats you’re tracking, so that you can authoritatively say how much of performance gain you got by getting a faster CPU, installing extra RAM, or upgrading your Linux kernel.

Complete presentation is down below:

Posted in MySQL, Optimization, PHP, Programming, Security at July 28th, 2008. 3 Comments.

This submission to Current.TV is pretty funny - Facebook News Flash - what News Feed would like if it were read by a TV news anchor.

Posted in News at July 27th, 2008. No Comments.

This is a response to A Programming Job Interview Challenge #13 - Brackets. The solution is in PHP, which hopefully is not an issue. Read More…

Posted in Programming at July 21st, 2008. 1 Comment.

image I am reading Starbucked by Taylor Clark, and the book is quite enjoyable, both as a look inside the coffee industry, and as a business case study of Starbucks. Clark dedicates an entire chapter to fair trade coffee practices, that I wasn’t too familiar with, but as anybody else, assumed it was a Good Thing. Fair trade coffee practices, controlled by a non-profit TransFair USA, pay farmers participating in the program $1.26 a pound for regular coffee, and $1.31 for certified organic. Under the fair trade label it’s resold to you at $12-15 a pound, making the retailer quite a winner in this transaction (originally fair trade was supposed to eliminate the middleman, and thereby lower the final cost of coffee).

When the price of coffee beans can occasionally go under 40c, this seems like a good deal, if you’re a coffee farmer, so what’s the catch?

  1. Fair trade contracts are binding, and requiring the coffee bean farmers to commit to $1.26-$1.31 even if market surges (as it does when there’s a cold summer in Brazil). Ok, this is a bit hypothetical, but coffee markets have been known to swing wildly nevertheless. In 2006 Starbucks (the largest seller of fair trade coffee in the US) has actually paid its non-fair-trade growers an average of $1.42 per pound. Oops.
  2. TransFair requires that each coffee farm participating in the program be coop-owned and employ no outside seasonal labor. This rules out private farms, family-owned farms, and corporation-owned farms. A family of coffee bean growers starts out a farm, hires seasonal labor to pick the beans, and wants to sell it as fair trade coffee? TransFair doesn’t let those capitalist pigs get anywhere near the application form.
  3. Roasters admit that fair trade coffee is of inferior quality. While the rest of the coffee farms have to compete in lower-priced open market, they frequently do it by quality of their product. When a fair trade farm is guaranteed $1.26-$1.31 a pound, the economic rationales start to take over, and growers always try to cut their costs to enjoy higher profit margins.
  4. TransFair requires every participant in the fair trade program - retailer or coffee grower - to sign a release form promising never to criticize the program in public.
Posted in General, Health, Money at July 16th, 2008. 4 Comments.

Back in 2007 HitWise published the findings that 1% of searchers conduct 13% of searches, and hence these power searchers became the coveted audience among the search startups. Most of them try to get to the 1% through some sort of rewards club. Live Search Club promises prizes in exchange for the searches conducted on Live.com.

Scour now combines Google, Yahoo! and Live results into a single interface, and pays out 1 point for searching, 2 points for rating a search result in a Digg-style manner, and 3 points for commenting on a search result, hinting at some attempt at social search. What do points get you? 25k points equal a $100 gift card, half of that is a $50 gift card, and 6,500 points equal a $25 gift card.

I was always happy to sell my Firefox searchbox to a highest bidder, and used to use Blingo, where I even won some movie tickets occasionally. Lately Blingo dropped Google search results, and substituted them with a combo of paid ads and organic results from Yahoo! and Live (bad idea because of paid links appearing in top 3 results for anything), so Scour looks like the next best thing to come after that. Currently 34,000ish rank on Alexa, but climbing quite fast.

Sign up through my referral, if you’re interested. The results pages seem to be clean, although navigating to the results page is always accompanied by a frame that has the ratings widget.

Posted in Money, Technology at July 13th, 2008. 4 Comments.

Today I applauded Rep. Jackie Speier’s first bill, introducing a nationwide speed limit of 60 in urban areas and 65 in not so urban areas. After I was done applauding, I was left wondering why would Rep. Jackie Speier pander to the interests of car and gas lobby, and not be more resolute as a junior Congresswoman.

While 60 is a nice first step, 0 mph speed limit would deliver the ultimate efficiency, and allow Americans to save a lot more money on gas. Scientists have shown that a great variety of vehicles, even Cadillac Escalades, break mileage records when driven at 0 mph. Driving cars at 0 mph can save up to 100% of gas expenses of an average American family.

I can’t help but agree with the following statement:

"There is no need to wait for OPEC or the oil companies to help us out," Speier said. "Every driver can effect change simply by easing up on their right foot."

Congressperson Speier is not afraid to speak the truth, and tell it like it is. As drivers, we should all reduce our oil dependency and stick it to OPEC by easing up the right foot, moving it one pedal to the left, tapping it slowly, then tapping it some more until the vehicle achieves complete stop.

Posted in News at July 11th, 2008. 3 Comments.

Both Northwest and United airlines today took time from their busy schedules to send me an e-mail urging to visit StopOilSpeculationNow, and craft a letter to my respective Congressperson, asking The Man to stop, well, oil speculation, and moreover, do it now (or by next weekend, if they’re too busy). The site teaches you what speculation is all about, and an unbiased opinion suggests speculators are buying oil future contracts in large quantities, therefore driving the price of crude oil up.

I am glad the issue is clear-cut, like the Batman movies. On one hand you have the evil guys, represented by oil speculators, on the other ones you have the noble truth-seekers, i.e., large airlines.

I was ready to fire up the typewriter, when the liberal media influenced my fragile mind yet again. None other than CNN Money insists that markets with future contracts actually are less volatile than those without futures (and speculators):

The volatility has been so extreme that the son of one of the original onion growers who lobbied Congress for the trading ban now thinks the onion market would operate more smoothly if a futures contract were in place.

Oops, I guess a lot of companies buy futures to hedge their bets against prices going up, not to encourage price increases. The Economist also takes a look at the commodities and futures markets blame game that’s unveiling, and introduces us to the concepts of supply and demand:

Speculators do play an important role in setting the price of oil and other raw materials. But they do so based on their expectations of future trends in supply and demand, not on whims. If they had somehow managed to push prices to unjustified heights, then demand would contract, leaving unsold pools of oil.

Not sure what’s causing the airline industry to react so viciously against crude oil futures trading. Perhaps we’re due for another price hike on airline tickets, and knowing the effort to stop crude oil futures would fail, airlines are conveniently setting up the scape goats.

Posted in Money at July 10th, 2008. No Comments.

One of the best editors for Windows - Notepad++, just hit a 5.0 release. If you’ve never heard of it, it’s a source editor for Windows written with Win32 APIs (and none of that .NET slowness that accompanies all of the latest apps) with syntax highlighting, code folding, and a few other features developed via plug-ins (such as FTP folder synchronization and HTML find-and-replace).

New version features a whole bunch of improvements to the typeaheads for popular languages, and auto-completion, common features for IDEs. Previously it matched opening and closing braces, now it matches opening and closing tags in XHTML. There are a few speed improvements, but since the editor was so fast before, I didn’t notice the incremental improvements.

Notepad++

Posted in Programming at July 7th, 2008. No Comments.