Changes in version 2.1.2

A place to talk about what is going on with Tera-WURFL's development, what will be included in upcoming releases and what you would like to see added to an upcoming version.

Changes in version 2.1.2

Postby kamermans » Wed Mar 10, 2010 2:06 pm

I'll post the changes I'm making here so you have an idea of what to expect in version 2.1.2.

So far, all I've changed is I renamed all the private methods to protected so I could extend them for the Tera-WURFL Explorer classes (10+ classes wirtten in two days, whew!).

By the way, I wrote an awesome little Google Sitemap class if anyone else is sick of dealing with sitemaps!
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Changes in version 2.1.2

Postby kamermans » Wed Mar 17, 2010 5:25 am

Well, I spent about 8 hours rewriting the WURFL XML parsing/loading scripts hoping for a major speed increase by using XMLReader instead of SimpleXML.
Specifically, I have rewritten TeraWurflLoader.php and created the abstract class TeraWurflXMLParser as well as two more classes: TeraWurflXMLParser_XMLReader and TeraWurflXMLParser_SimpleXML.

End result: SimpleXML was faster than XMLReader to begin with, and appears to use less memory!

I was able to remove a bunch of old code that was unused and confusing from the 1.x versions and separated much of the logic in the XML parser, optimizing it along the way. It now parses about 15% faster on my machine, loading the WURFL with no cached data in 9.8 seconds on my laptop, which is quite a bit faster than before.

Code: Select all
Database Update OK
Total Time: 9.795273065567
Parse Time: 1.8240180015564 (TeraWurflXMLParser_SimpleXML)
Validate Time: 0.0045268535614014
Sort Time: 1.9420890808105
Patch Time: 0.16571807861328
Database Time: 5.5644080638885
Cache Rebuild Time: 0.29451298713684
Number of Queries: 304
PHP Memory Usage: 14.19 MB
--------------------------------
WURFL Version: www.wurflpro.com - 2010-02-03 10:31:00 (Wed Feb 03 10:35:26 -0600 2010)
WURFL Devices: 12883
PATCH New Devices: 38
PATCH Merged Devices: 2


The XML Parser that is used to process the wurfl.xml file (and patch files) is determined by TeraWurflXMLParser::getInstance() as follows:

Code: Select all
   final public static function getInstance(){
      if(function_exists('simplexml_load_file')){
         require_once "TeraWurflXMLParser_SimpleXML.php";
         return new TeraWurflXMLParser_SimpleXML();
      }elseif(class_exists('XMLReader')){
         require_once "TeraWurflXMLParser_XMLReader.php";
         return new TeraWurflXMLParser_XMLReader();
      }else{
         throw new Exception("No suitable XML Parser was found.  Please enable XMLReader or SimpleXML");
      }
   }
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Changes in version 2.1.2

Postby kamermans » Wed Mar 17, 2010 10:21 am

I also improved the performance of fall back tree lookups by using a stored procedure to find all the parents of a given WURFL ID. I tested many methods to speed this up, including a left<->right nested set model to allow me to find an entire fall back tree using a since self join, but in the end all WURFL ID lookups result in less than 16 queries (16 fall back devices), so I found the following to be the fastest method:

Code: Select all
CREATE PROCEDURE `TeraWurfl_FallBackDevices`(current_fall_back varchar(128))
BEGIN
WHILE current_fall_back != 'root' DO
   SELECT capabilities FROM TeraWurflMerge WHERE deviceID = current_fall_back;
   SELECT fall_back FROM TeraWurflMerge WHERE deviceID = current_fall_back INTO current_fall_back;
END WHILE;
END


Then I just iterate through the result sets via MySQLi::next_result().
This will drastically increase performance for configurations where Tera-WURFL is separated from its database since it only needs to send one query to get the entire fall back tree and build the capabilities array.

P.S. If you want higher performance, don't forget to set MySQL's query_cache_size to something reasonable like "50M". This will give you a tremendous speed increase on your cached device lookups.
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Changes in version 2.1.2

Postby NCoDer » Thu Jul 15, 2010 7:11 am

It seems there is a bug in TeraWurflDatabase_MySQL5.php:
The prefix from config is not considered in two CREATE procedure queries. (In the one you quoted for example).

So if someone changes the default table prefix of the MERGE/INDEX/CACHE tables it gives an error.

I wanted to attach a patch but this forum allows neither .txt, .patch, .diff files (???)
So here it is:
Code: Select all
line 244
-          $nest = new TeraWurflMySQLNestedSet($this->dbcon,'TeraWurflMerge','TeraWurflIndex','deviceID','fall_back','lt','rt');
---
+          $nest = new TeraWurflMySQLNestedSet($this->dbcon,".TeraWurflConfig::$MERGE.",".TeraWurflConfig::$INDEX.",'deviceID','fall_back','lt','rt');


line 464/465
-    SELECT capabilities FROM TeraWurflMerge WHERE deviceID = current_fall_back;
-    SELECT fall_back FROM TeraWurflMerge WHERE deviceID = current_fall_back INTO current_fall_back;
---
+    SELECT capabilities FROM ".TeraWurflConfig::$MERGE." WHERE deviceID = current_fall_back;
+    SELECT fall_back FROM ".TeraWurflConfig::$MERGE." WHERE deviceID = current_fall_back INTO current_fall_back;


By the way: Thanks for this great application!
NCoDer
 
Posts: 1
Joined: Thu Jul 15, 2010 6:58 am

Re: Changes in version 2.1.2

Postby kamermans » Mon Jul 19, 2010 8:00 am

Thanks for the heads-up. I actually put this in the development code a couple weeks ago so if you need to use an alternate prefix you may download the beta code from github (http://www.github.com/kamermans/Tera-WURFL).
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX


Return to Improvements / Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron