Seva's notes

Wisdom, Awareness, Responsibility :)

Posts Tagged ‘LinkedIn

Competing design attributes: performance vs. maintainability

leave a comment »

Q. Is performance more important than other attributes like ease of use, maintainability etc? When designing your new code, what level of importance would you give to the following attributes?

A. You should not compromise on architectural principles for just performance. You should make effort to write architecturally sound programs as opposed to writing only fast programs. If your architecture is sound enough then it would allow your program not only to scale better but also allows it to be optimized for performance if it is not fast enough. If you write applications with poor architecture but performs well for the current requirements, what will happen if the requirements grow and your architecture is not flexible enough to extend and creates a maintenance nightmare where fixing a code in one area would break your code in another area. This will cause your application to be re-written. So you should think about extendability (i.e. ability to evolve with additional requirements), maintainability, ease of use, performance and scalability (i.e. ability to run in multiple servers or machines) during the design phase. List all possible design alternatives and pick the one which is conducive to sound design architecturally (i.e. scalable, easy to use, maintain and extend) and will allow it to be optimized later if not fast enough. You can build a vertical slice first to validate the above mentioned design attributes.

(c) Whoever

Written by Seva

2010-03-16 (March 16) at 12:51:42

Posted in development, integration, software, thought

Tagged with

Is Facebook PHP HipHop bullshit?

with 17 comments

Update: with the release of HHVM 2.0 the below becomes entirely obsolete. Cheers!

Yes, it finally happened – Facebook announced the PHP to C++ translator. Hurray!
So, after reading the post I can assume it:

  1. parses PHP code,
  2. extracts PHP AST,
  3. converts to C++ AST and
  4. generates C++ code.

Honestly, it’s not the best way of optimization, but probably is a quick win (BTW, why did it take for them so long?), which theoretically might indeed generate efficient C++ code.

But wait, what do they report? “We’ve reduced the CPU usage on our Web servers on average by about1 fifty percent3, depending on the page2.”

I have some doubts:

  1. Where is the objective and comparative statistics?
  2. Did they even collect the general statistics, or just tested some pages to see the difference?
  3. 50%? That’s it? And how about the fact that C++ is actually 3-500 times faster (also here) (That would be 70% to 99% reduce of CPU). In fact the well known PHP Accelerators provide the same level of performance improvement as HipHop! It’s interesting, did they try any of them before entering the so called “Hackathon”.

In addition to reflections above, looking at the profiles of 2.5 coders which hacked the translator, I sorrowfully tend to estimate that the answer for the question in this Post’s subject is positive. Nevertheless I’m full of sincere hope that further info will dispel my suspects and prove that HipHop is actually a brilliant peace of software.

Written by Seva

2010-02-03 (February 3) at 02:05:49

Posted in development, integration, php, software, thought, web

Tagged with

FreeBSD MySQL MyISAM multi-CPU concurrency performance

leave a comment »

Recently we had a performance issue with multiple plain concurrent requests on a MyISAM table – the process list reported that all selects get stuck for very long time while Sending Data. After many tests we discovered that:

  1. The problem only occurs when running on multiple CPUs;
  2. The problem only occurs when running on FreeBSD OS.

After searching over the Internet we found, that this class of problems is being reported since antique versions of FreeBSD and, despite the claims it’s fixed with each version, it persists even in fresh 8.0.

So the decision was to install Linux on all the DB servers.

There is an alternative option though – it’s possible on FreeBSD to install MySQL of any version with WITH_LINUXTHREADS=yes parameter and it will be benefited from the Linux thread model.

Written by Seva

2010-02-02 (February 2) at 06:03:24

Posted in db, FreeBSD, hardware, integration, linux, software

Tagged with

Download a Google Document with Zend_GData API

with 3 comments

Today I’ve thought of a way of showing a private Google Document on a custom page with no need to authenticate. I was surprised that the issue was not covered in any documentation; I also didn’t succeed to find a quick solution on the Internet. Thus I’m sharing with you the solution using Zend_GData library, my dear friend, with hope to save your valuable time:

$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, Zend_Gdata_Docs::AUTH_SERVICE_NAME);
$api = new Zend_Gdata_Docs($client);
$doc = $api->getDocument($docId);
$response = $client->request();
$html = $response->getBody();   

Voila! The $html variable now contains the clean and image/css/js safe content to use (including <HTML> tags)

Note: The code lacks exception handling for simplicity, so please keep that in mind and fulfill upon need.

Written by Seva

2010-02-01 (February 1) at 06:35:51

Variable declaration in PHP

with 2 comments

Today while playing around PHP and stuff I have been thinking of patterns of handling optionally existing variables.

The 2 most commonly used ones are:

if (isset($var) && $var != null) doSomething($var);
// or
if (isset($var) && $var != 0) doSomething($var);
// or
if (isset($var) && ($var != '') doSomething($var);

if (!isset($var)) $var = something();

However my experience points me that in the majority of the cases it’s enough to check the boolean value of the variable to proceed:

if ($var) doSomething($var);

if (!$var) $var = something();

Which reads very kosher. But then we have a problem of getting notice that the variable is undefined, which is not kosher.

So the way kosherize the snippet is to enforce variable definition before usage. Meaning we would like to either use its value if it’s defined, or to initialize it with null. But of course I don’t like to use isset() for that. So what to do? I found an answer!

$var = &$var;

As you can see in this way you declare further usage of the variable. If the variable exists – it does nothing. If it’s not it is silently initialized with null. No notices are yielded. Also it’s better than if(isset()) combination because of readability – the only alphanumeric tokens on the line are variable names.

Isn’t it nice?

Written by Seva

2009-09-28 (September 28) at 02:21:10

Posted in development, php, thought

Tagged with


leave a comment »

Shame on me! I’ve discovered that provides syntaxHighlighter functionality just today. So I hurry to report that the only 2 posts in this blog, which contain code snippets have been immediately converted:

<a href="">
    Copying nodes between XML documents with Java DOM
<a href="">
    Prototype styled Google Analytics javascript snippet

BTW, isn’t it weird I don’t have one snipped in PHP yet?

Written by Seva

2009-09-16 (September 16) at 09:14:52

Posted in html, java, javascript, php, software, web, xml

Tagged with

Moving on

leave a comment »

Today was the 1st day of me working in the new company (yes, my dear friend, I bid farewell to Nielsen Online) – EasyToBook GmbH – as Software Architect. Unfortunately I’ve got no chance to either design any architecture or to develop any software yet, but succeeded to meet nice and talented people and spent some sweet time reading the documentation.

Written by Seva

2009-08-26 (August 26) at 10:21:12

Posted in development, future, php, software, web

Tagged with