Wednesday, August 11, 2010

Chess Competition Problem?

To one of my friends one of Google's engineers presented his data at Berkeley which I saw through a telacast at Merced comparing optimized with unoptimized algorithms sorting a dataset for accuracy. What he found was that as the size of the dataset increased (and assuming related increases in machine power) was that the unoptimized algorithms outperformed and better handled different test cases (such as different languages) much more easily. In fact the optimized algorithm accuracy rose at a linear rate while the unoptimized algorithm increased at an exponential rate.

So I wonder if that's a problem with the chess competition, the dataset might be too small to future proof the algorithm. Hmm....

Ciao

Update:
Here is the link.
http://www.citris-uc.org/events/RE-fall2009

Thursday, August 5, 2010

Fixed the Android Problem

Fixed the seg fault with android.

findViewById returns a null if you cast an object that the casting was not compatible with.


Such as a checkbox


ch = (CheckBox) findViewById(R.id.check);
So for whatever object you seek to fetch you must declare it like such in the XML file.


android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="This checkbox is: unchecked" />


NOT 


android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="This checkbox is: unchecked" />

As you might leave in due to the automade boilerplate code.



It's an easy mistake to make....

Ciao

Monday, July 19, 2010

How to Distribute a GNU Linux Game Binary

What thing I keep looking for-on the tubes-is how to wrap up a binary with game data and distribute it online. Think a demo. Even in Windows you have to use Visual Studio-which I don't want to do-I want to know how to do it manually.

Anyone have any clues? Feel free to post!

Ciao

Friday, July 16, 2010

I don't understand why people are raging on Obama

I don't know why people are raging on Obama so much. He's cut your payroll taxes, standardized health care to eliminate paper work waste (I don't have to hire a constant now to give my employees a medical plan-I save ALOT of money.) and cut the wasteful F-22 program (George W. Bush spent years trying to cut that!). Plus we have credit card reform to eliminate harmful lending.

I personally think the herd mentality is ganging up on Obama because he promised the moon and only delivered half of the moon to our doorstep. (The stimulus program will cause waste! Oh no! When has that ever happened!?) People were worried about a collapse and the stimulus averted that herd panic-that's all that is went meant for-providing funds to fix broken bridges and roads was secondary. (Herd panics are important-if everyone withdraws there savings, the bank system will collapse and small businesses that provide 80% of the jobs of the American economy can't get funding to handle tough times, to expand or even start.) 

The reason you don't have jobs in this economy is people rather enter real estate (and construction) and get rich quick then enter harder fields such as a science or even a trade (electrician) that make things or develop real expertise that can be sold. No magic wand Obama will wave will change that.

In my opinion the only thing he deserves flak for is the banks (well that and offshore drilling & ACTA treaty), namely with AIG. AIG with government money still insurance upto a 100% rather then the government use it's power as a sovereign entity to change the contracts to make it 95% or 90%. Since banks are guaranteed a full return of there money they just foreclose on the homeowners rather then work with them and pocket the money.
-
Ciao

Thursday, June 24, 2010

Cosmic Rays!

Seems I need a server with ECC RAM. Awesome runthrough of debugging techniques which you can never find in once place.... current.

http://blog.ksplice.com/2010/06/attack-of-the-cosmic-rays/

Ciao

Thursday, June 10, 2010

Bad MySql Tutorials - Don't teach me an out of date interface!


Great...

There are two interfaces for php-mysql... and i've been using the older, slower, not designed for php one.

All the tutorials I found were for the older one. :-/

Plus there is this fine note in addition.
---
With versions of PHP 5.3 and newer, you can alternatively use the new MySQL Native Driver with mysqli. This gives a number of benefits over using libmysql.
To use MySQL Native Driver with mysqli you need to configure the PHP source code using the --with-mysqli=mysqlnd option, prior to building PHP.
This is the recommended option, as using the MySQL Native Driver results in improved performance and gives access to features not available when using the MySQL Client Library. Refer to What is PHP's MySQL Native Driver? for a brief overview of the advantages of MySQL Native Driver.
---


Ciao
--- update---
Here's a nice tutorial
http://devzone.zend.com/article/686

Siege!

I used an alternate tool called Siege to test my app and phpmyadmin. Siege turned out to be far closer to my profiling then ab (Apache Benchmark) tool was. Maybe i'm not using it right... I haven't even looked at the docs. Never the less phpmyadmin is very slow, much slower then my app which can handle around 200 persistent connections in vbox before becoming a little unstable.

The nice thing about siege is that I can use it to simulate peak load instead of handling a set number of users.

Ciao

Sunday, June 6, 2010

Why .Net is fast

This nice link explains all
http://serverfault.com/questions/88283/performance-of-iisasp-net-vs-nginx-fastcgi-mono-or-xsp

-
I am actively developing in both PHP & ASP.Net. I can't claim deep knowledge of IIS, or NGINX but I am VERY familiar with Apache and Lighttpd.
ASP.Net uses a threaded architecture that is very much a part of the web server it's self. Static variables retain their value between requests and in between users. This is where ASP.Net get's most of it's speed advantage from. The shared memory is stored inside each individual process, and between threads. Separate processes do not share memory. So when you scale beyond one server, much of this advantage is lost.
PHP is built in the old fashion CGI style, where each request is a blank slate. This means that any common information either has to be fetched from a common store or entirely regenerated. PHP is NOT slow, it is different. Most major operations in PHP are calling modules written in C, so they are lightning fast. PHP executing on it's own is not as fast as a compiled language, but is by no means slow. There are (very common) modules for PHP which cache compiled (in memory) versions of the code, and can increase performance between 4 and 10 times.
PHP has been around for a while, and many solutions to it's CGI style exist. xcache offers a value store very similar to ASP.Net's static variables. Memcache offers a slightly slower but better scaling (between physical servers) solution to persistent shared variables.
ASP.Net offers much more formalism and structure. But bad programmers can make a mess in any language. If you choose ASP.Net you should investigate some of the excellent NON-Microsoft libraries for development. (eg NHIbernate & http://www.castleproject.org/)
My personal preference (when i'm not paid to do otherwise) is PHP. Even though it takes a speed penalty, it is easier to develop in and less complex to scale up (even if it would require more PHP servers than .Net). Servers are much cheaper than programmers.
In either case any Web > 2.0 application will be data bound, and the database configuration will have a much more profound impact on performance than the language choice.
-

Ciao

P.S.
If your user31472 and you have a problem with me posting your long quote-let me know in the comments. On serverfault i'm csdreamer7.

PHP and Mary - Speed!

As I tease you-my friends-endlessly about. I'm building a high volume-low overhead website like Markus did with Plentyoffish.com called Mary. It is not a dating website but I hope to make Mary into a low workload million dollar website with adsense. To encourage women to go into computer science I give all my projects cute girl names-these serve as the generic free software names. Plus for mine it's a hint on what it does.

I decided at first to use PHP and MySQL because as the most common platforms they would be the best supported and have the most mature tools. That reasoning was very good. I easily setup Ubuntu by downloading the packages-it did all the hard work for me. I was also able to get phpmyadmin working out of the box as well. Got MediaWiki set as well with a bit of configuration.

I ran into database issues when I realize how difficult joins could be to design. I tried comparing other platforms such as noSQL databases. Then I began thinking how much Mary-which right now does nothing more then display a fancy template and connects to a database to do some admin tasks-compares against other. Once again Ubuntu package maintainers did the hard work for me and apt-get installed xcache and xdebug to speed up and profile my applications.

The packages installed but I still have to configure them. I used this tutorial to setup xcache and xdebug.
(1) http://www.ibm.com/developerworks/library/os-php-fastapps1/
(2) http://www.ibm.com/developerworks/opensource/library/os-php-fastapps2/?S_TACT=105AGY82&S_CMP=MAVE

I'm too lazy to post the data. I discovered that my index.php spent most of it's time on the require_once(common.inc); function call.

Okay... why? Why is it important?

I used the ab (apache benchmark) comparison tool to test Mary's index.php to phpMyAdmin index and phpMyAdmin blew it's socks off. That couldn't be possible and I spent many days playing with it to discover why. Including comparing phpMyAdmin to an empty file or no file at all-it still beat it. That stumped me... my best thought was that phpMyAdmin was redirecting ab. (There were no failures.) Mediawiki produced similar results, however when compared to there main page
/mediawiki/en/MainPage.php (I think) they slowed down to a screeching halt-which made sense.

Mary's unmodified time as of 0.3 is 30 seconds for 10,000 requests for the index.php by ab.

Now back to require_once(). I have a topology to my early program as such.
defs.inc
dbmysql.inc template.inc
common.inc
index.php admin.php search.php... etc

common.inc is included in every bottom .php file for my convenience. It was also where the php interpreter was spending most of it's time. Interesting it didn't do that for the require_once of defs.inc or dbmysql.inc nor the template.inc generating function. Using require instead shaved about 30% of the time off that was spent including common.inc. So I just ripped it out and just used the template.inc-the index.php ran a fraction of the time... according to the debugger.

In a deeper issue to expose programming issues. Markus reported that in ASP.net that he everything dynamically generated-switching between html and ASP tags actually slowed down the interpreter in the long run. My template function is very simple-taking the name and the body of the text to display and wrapping the html and css around it-all dynamically parsing strings to be echoed at the end. I thought it might be different in PHP-or at least curious-I rewrote the 30 lines of code to go in and out of PHP tags. ab reported a 20 vs 23 second improvement per 10,000 queries (3 seconds). Since I am running the cache and the debugger at the same time I imagine it was due to the cache handling the html and the broken up echos better then one single echo. I forgot to add a few echos down below to print my name, date and version number of Mary. This is extra work so php should have slowed down... it actually improved to 18 seconds. Once again I think this is because of the echo's being broken up so apache worker threads more efficiently switch between inteperting and printing out html rather then hogging the output and stepping on each other's toes. I plan to stick with Markus's advice because of a fear of premature optimization plus my template function can be broken down into three echo's and have it's performance compared to that (a real application will have database lag to act as a buffer).

ab still reported phpmyadmin beating up Mary's index (15-17 seconds). Comparing phpmyadmin's profile to Mary's index reported similar comparisons in the debugger which was odd. I didn't even come up with an explanation for this... I need to read the source code to find out if it is just redirecting like Mediawiki was.

So I was out looking for the info and came across this.
(3) http://stackoverflow.com/questions/186338/why-is-require-once-so-bad-to-use

"
The other downside is APC doesn't cache include_once and require_once calls IIRC – dcousineau Oct 10 '08 at 7:20
"

Damn.

Further research came up with this.
(4) http://sb2.info/php-opcode-caches-require_once-is-slow/

"

If you got a large OO PHP application, you usually come with many files included using “require_once()”. Different test from different sources shows that using require_once works up to 4 times slower than require. Basically, all known PHP opcode caches suffers from this issue (APC, XCache, ea/mmcache).
There’s patches committed in APC that focus on this problem. They override INCLUDE_ONCE/REQUIRE_ONCE opcode handling whenever possible, although a bit ugly. This isn’t done in XCache yet. Ugly because isn’t not that php-src support caches, but caches support php-src.
Solution: general advice here is replacing all “require_once()” calls with “require()”, it should speed up the application.
"

Great.
Out of habit I just require_once with all my function calls. (3) has a deeper explanation. Includes are very expensive and should be used rarely. As compared to being a C programmer where you include everything at the top of the file and having the program so nicely organized as you know the complier will optimize everything and make your program run so nice.

It's funny how php can remind you of assembler.

Anyway... i'm not going to worry about speed right now and just go back to developing the database functionality and view. The includes are easy enough to clean up for optimization. Plus I have been looking at Facebook's HipHop and I like it. I will use when program actually get's bogged down and compile it.

Ciao

Thursday, April 15, 2010

What is Freedom Software?

In a nutshell Free Software. I call it that because i'm sick of explaining how to make money off 'Free' Software. You can make a very successful business off Freedom Software.

Yes, code should be free. Yet with something you can't sell like speech, it makes sense to call it free. Doesn't mean it works with tangible objects... or things we define as things even thou is a form of speech, or copyrightable expression.

Free Art! Free Manuals! Free Kittens!
Free Art for sale! Free Instruction Manuals for sale! Free Kittens for sale!
Doesn't work.

When you call it freedom it has a different cultural meaning for Americans. I admire Richard Stallman very much but I have been saying it around abit and I feel it has momentum.

Plus it's a pun on Freedom Fries.

Ciao!

Why I will not develop on the iPhone or the iPad

I keep having my CS friends ask me why I won't develop for the iPhone or the iPad. So I post this for them to read... maybe weep too.

As a gadget geek I love Apple's products. I claim my iPod was made by forest elves-not stumpy, little Santa elves-Lord of the Rings, bow shooting, orc slaying, fangirl bait elves. I played with the iPad that one cs31 student brought in. It was glorious, very responsive, barely weighted anything, the interface effects were beautiful.

I won't buy it. I won't develop for it.

I know Apple; they will never let me own it. I paying them the privilege to use there wonderful combination of software applications and a tightly coupled OS. With payment I get this nice mass of plastic and circuits for free. With an easily scratched screen-built in non-exchangeable battery-drm. I'm renting it. I have pay a replacement renting fee every three or so years because the graphics card fried up (happened to my iMac), the battery died and Apple charged me the same as a new iPod.

It's even worse if your developing applications.

First I can not talk about the API internals... anything that I learn.

Second... and implied... I can not make Freedom Software as the developer's license forbids public code. That is unacceptable-I love freedom software. It gives me many features: like open code ensuring that one developer did not put in spyware in the build to sell my credit cards to Russia. (Hint: don't bother unless you can buy a new house with three cents.)

Third if I sell a hundred applications... and all those customers return it, citing that i'm a dush. Apple would take a 30% cut of the revenue of a normal sale. They would not return that 30% to me and I would be on the hook and own Apple 30% *100 *whatever I charged. (They learn from the music industry so well-the music industry will sign up a new artist, charge them for all advertising for there music, stastically you will lose money on your album instead of gaining it unless your britney spears, you'll make most of your money through concerts.)

Forth-they now ban any other language besides C, C++ and obje-C. Not that I was a fan of Monotouch, I did think it was cool that they made a C# complier that would easily work with the Cocoa API.

So I don't own my application either. If I did, I would at least be able to post the code. I have little, if any freedom.

There is Android... not as sexy, nor functional, nor as cool of an app store. Plus Apple is an established, well known brand with the iPod touch, iPhone and the iPad. That may bring a certain security in that I have a market I can sell to.

However as an American I feel I should choose it over Apple.
"Any society that would give up a little liberty to gain a little security will deserve neither and lose both." Ben Franklin
The man knows our modern coding dilemma.

Plus the Apple market may not bring much security in the first place.
http://apprejections.com/
Adobe used to be one of Apple's biggest supporters but things changed and now Apple is trying to push them off. It's fun being a developer to a company that treasures you.

One CS senior told me that the problem was with the developers not Apple. He had been programming since the 70's and had a lot to say to me. He told me if you programmed with Apple's API back when the mac was in black and white. Your applications would have color when the computers were upgraded to color displays. He told me the that these are appliances directed towards average users; not computer scientists like himself or myself. He told me Apple was a forward thinking company that innovated. (Even if Steven Jobs hated the cd-rom while Bill Gates pushed the Microsoft board to model there software line around it. Couldn't resist ;-) ) I thought there were alot of holes in his argument that didn't address what I put above. I have no intention of posting my replies behind his back on this blog. Better to tell him in person. I just thought his point of view was interesting. (Plus Adobe's refusal to update Photoshop to the Cocoa interface.)

Finally, a lab mate in cs31 told me that while the sdk to Apple's tools were free. You need to get the 99 dollar developer license to distribute applications. He seemed surprised when I told him that Google only charged a one time fee of 20 dollars.