Archive for the ‘Random Thoughts’ Category

Lunch

Random Thoughts | Posted by apokalyptik
Mar 03 2010

I make a fruit salad kind of thing almost every single day for lunch. And for some reason, today, I thought I would record the process. This is how I make a fruit salad… How do you do it?

for the record this is not an exciting or cool video… its just me… cutting up fruit… silently

Nikki In Training

Random Thoughts | Posted by apokalyptik
Feb 09 2010

I just want to share with everyone how proud I am of my Nikki. She’s been training to do a half marathon for charity (and to get into shape.) She’s just been stellar about it. She’s walking tons, and lost a bucketload of weight. I’m sure that she would love it if anyone wanted to drop by and give her some words of encouragement on her blog where she’s keeping a log of her Journey. Thats my wife!

This is actually pretty cool

Random Thoughts | Posted by apokalyptik
Jan 14 2010

First person tetris… awesome… http://www.firstpersontetris.com/

Time based bloom filters

Business, PHP, Personal, Random Thoughts, Ruby (on or off) Rails, SRSLY, Software Development | Posted by apokalyptik
Jan 06 2010

I find this concept fascinating and plan to investigate further down this road.

lockd, a memcached like locking daemon in php

Random Thoughts | Posted by apokalyptik
Dec 10 2009

You might have seen my last post about this code (here) if you are one of my 2.3 loyal readers ;) . It wasnt nearly so complete or robust then (segfaulting? come on! right?)

The segfaulting was caused by stupidly using $this->function() from inside of $this->function() for recursion, overloading the stack. Note to self: don’t be lazy about recursion :D

If you’re interested in the project I have it setup over here: http://code.svn.wordpress.org/lockd/ so please feel free to try it out.

 

What is it?  It’s a network based locking mechanism.  You can connect to it over TCPIP and get either exclusive or shared locks for as many arbitrary strings as you like.  Shared locks have the added benefit of being counted.  You can query to see if a string is locked (and how many times for shared locks.) You can also release locks.

 

All of this is useful, but… The nice thing about lockd, though, is that if your client disconnects (say the process which had locked a string quit unexpectedly) lockd will automatically orphan those locks for you.  So you have no need to try and cleanup and guess the lock state of a failed process.   And since this runs as a network daemon you can have as many of them as you like.  You can use them for local (locks on the same box) or distributed (locks on the same resource from many boxes.)  It also comes with built in stats which you could hook up to munin, or nagios, via netcat without too much trouble.

 

The protocol is also extremely simple

  • g (string) — get an exclusive lock on the string
  • sg (string) — get a shared lock on the string
  • r (string) — release an exclusive lock
  • sr (string) — release a shared lock
  • i (string) — inspect an exclusive lock
  • si (string) — inspect a shared lock
  • q — query stats
  • q full — query stats and dump the exclusive and shared lock arrays

 

Thats it.  “(int) (string)” is returned for these commands. where (int) is for programmatic use, and (string) is for human consumption.

 

We use this with the Jobs system (also available as an OSS project) for WordPress.com, Intensedebate, Gravatar, and more, and is currently handling nearly a million operations per day… per server…

 

This is Itch-Scratch-Ware at its finest.

This made me laugh :)

Random Thoughts | Posted by apokalyptik
Nov 26 2009

The Adventures of Lil Cthulhu

Funny Stuff, Random Thoughts, WTF | Posted by apokalyptik
Nov 17 2009

php debugging the really really hard way

Bash, Business, CLI, Linux, PHP, Random Thoughts, SRSLY, Software Development, WTF, Web Stuff | Posted by apokalyptik
Oct 06 2009

If you’re ever in a situation where something is only happening intermittently, and only on a live server, and only while it’s under load… Lets say its not generating any error_log or stderr output, and you cant run it manually to reproduce… (we’ve all been in this situation) How do you get any debugging output at all?

Step 1: add this to the top of your entry point php file

if ( $_SERVER['REMOTE_ADDR'] == '127.0.0.1' ) {
       error_log( ' :: ' . getmypid() );
       sleep( 10 );
}

Step 2: use curl on the localhost to make the request

Step 3: (this assumes your error log is /tmp/php-error-output) run the following command in a second (root) terminal window

strace -p $(tail -n 1000 /tmp/php-error-output | grep ' :: ' | tail -n 1 | sed -r s/'^.+ :: '//g) -s 10240 2>&1

Good luck…

My inner geek is really showing tonight

Random Thoughts | Posted by apokalyptik
Oct 02 2009

I think its the Penny Arcade posts… I really do… But lately I miss the old days when I used to play Magic the Gathering, or Dungeons and Dragons. Maybe some geek(s) out there in cyberspace and in the Pittsburg, Ca area will find this floating message in a bottle and reach out. Maybe not, and if they don’t maybe its for the better?

Some WordPress XMLRPC Love

Random Thoughts | Posted by apokalyptik
Aug 28 2009

So I had to help fix an internal issue on WordPress.com where some largsish bits of data are transferred around via XMLRPC. We like XMLRPC, its simple, extensible, and works. But one thing that the IXR_Server is not is ‘light’. Because of the way that it works all of the data is transferred base64_encoded which means that a 10mb attachment just grows and grows and grows in ram on the server side… Which is exactly the problem I was faced with. I spent about a full day pouring through the code and its current and peak memory usage at various places in the flow of execution and put together a patch to help address some of the most glaring memory hogs.

I asked Joseph to go over it and submit the good stuff upstream to the wordpress.org project (he’s had a lot more experience working with the actual xmlrpc clients than I do, so his experience there in making sure that they wouldn’t be disturbed by my changes was very valuable.)

The takeaway from this is pretty simple, but at the same time quite profound. When working with arbitrary data inputs that you expect to be large you really have to watch the copy-by-value operations that you do.  Referencing is one of those things that you may not need to know in detail for every day coding, but its good to be aware of them and have an idea of what they are/do.  In cases where you find yourself inexplicably running out of RAM a couple of references can save the day.

Related/restated take-aways are:

  • The idea of balacing two variables in ram by adding X bytes to one and then subtracting those xbytes from the other. (xml parsing)
  • Also that certain types of operations create a temporary variable in ram with which to work with your data, so limiting the amount of data they need to function can be helpful when the variable is of considerable size (preg_replace)

All in all this should be a considerable win for WordPress (dot com and dot org) xmlrpc users.  If you’re running a self-hosted wordpress install and want to test it out and comment on the patch i’m sure everyone would be greatful.

DK