CodeIgniter Forums
DMZ 1.7.1 (DataMapper OverZealous Edition) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DMZ 1.7.1 (DataMapper OverZealous Edition) (/showthread.php?tid=28550)



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]OverZealous[/eluser]
[quote author="Frank Liu" date="1269039113"]DMZ's main library file contains spl_auto_load function, which is not supported until PHP 5.1.2. So you may want to change server requirement to reflect this?

Anyway, can I just remove the spl_auto_load statement and find another way to load the files? Do you have a recommended way to deal with this problem? I am using php 5.0.0.[/quote]

I did not realize that (I've thankfully never had to deal with PHP older than 5.2, because I use the JSON functions a lot!)

I'll take your suggestion and bump the requirements up to 5.1.2. As for a work-around, all the spl function is doing is loading the models in as they are needed. I know I "broke" the ability to load models via CI (which will be remedied with 1.7.1), but you can temporarily fix that by removing the private in front of the _assign_libraries function in the main library. It's near the bottom.

Another option is to write your own helper or library, or even extension to DMZ that allows you to load the models in as needed.

Sorry to hear about your work environment! Confusedhut:


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]OverZealous[/eluser]
[quote author="Mareshal" date="1269043892"]
Is this normal?
[/quote]

First, ALL ORMs are slower than processing the query directly. They have to be! The benefit of an ORM is code-reuse, easier to read code, safer queries, and easier maintenance. Performance is what is sacrificed to make this.

DMZ uses the CI ActiveRecord. Are you measuring just the query? Or the entire page? How many runs did you measure? One run tells you nothing, because the server could be having a hiccup at that moment.

DMZ is an ORM — so remember that it has to instantiate each result as an object. 1.7 includes a new format, get_iterated, that allows the code to only instantiate items as needed, however, there are use cases for it. It doesn't replace every normal get.

Also, compare the queries being generated. Did you specify which columns to query? DMZ is pretty smart, but remember, it's automatically building a query. It doesn't have the ability to predict what you want, so it queries exactly what you ask.

Quote:And is there an option to build database from models?
No. DMZ uses the database to learn about the models, not the other way around.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]Mareshal[/eluser]
Code:
function test(){
        
        //DMZ Test
        $this->benchmark->mark('start');
        
        for($i=1; $i<=1000; $i++){
            $u = new User();
                $u->username = "test";
                $u->password = "test";
                $u->first_name = "test";
                $u->last_name = "test";
            $u->save();
        }
        
        $this->benchmark->mark('end');
        
        echo "<Br>DMZ: ".$this->benchmark->elapsed_time('start', 'end');
        
        
        //Active Record Test
        $this->benchmark->mark('start');
        
        for($i=1; $i<=1000; $i++){
                $insert['username'] = "test";
                $insert['password'] = "test";
                $insert['first_name'] = "test";
                $insert['last_name'] = "test";        
        
            $this->db->insert('user', $insert);
        }
        
        $this->benchmark->mark('end');
        
        echo "<Br>Active Record: ".$this->benchmark->elapsed_time('start', 'end');

    
    //Pure SQL Test
    $this->benchmark->mark('start');
        
    for($i=1; $i<=1000; $i++){
        mysql_query("INSERT INTO `user` (`username`, `password`, `first_name`, `last_name`) VALUES ('foo', 'bar', 'chh','asdasdasd')");
    }
    $this->benchmark->mark('end');
        
    echo "<Br>Pure SQL: ".$this->benchmark->elapsed_time('start', 'end');
    
    }

DMZ: 1.9113 , 2.0543 , 2.2763 s
Active Record: 1.7360 , 1.5230 , 1.6436 s
Pure SQL: 1.2210 , 1.1639 , 1.2076 s

How did I run them?
On DMZ run, AR and SQL were commented
On AR run, DMZ and SQL were commented
On SQL run, AR and DMZ were commented


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]OverZealous[/eluser]
@Mareshal
First: those numbers aren't that far apart. Remember that everything the raw SQL does, the AR method has to do, and everything the AR method does, the DMZ method has to do.

Second: DMZ validates the data on every save. This is on purpose, and one of the key reasons to use it.

Third: DMZ looks up the ID after each insert, effectively doubling the number of queries.

I know this is a test, but you are dealing with absurdly small numbers here.

Basically, there's nothing else to say. DMZ is going to be slower, as I said, because it is a wrapper around AR which is a wrapper around SQL.

Heck, I'm more amazed that the overhead is so low, given that you are creating 1000 independent objects (actually, it's probably closer to 3000-4000 objects, with the error, db, and other classes), running 1000 validations, AND DMZ is actually running at least 2x as many queries! And this is over the straight ActiveRecord version.

Don't worry so much about optimization. The overhead used by DMZ is actually insignificant compared to the database and other PHP code in nearly every application, unless you are really trying to use it incorrectly. ;-) (Well, at least in 1.7, since you can use get_iterated to iterate over large result sets. Which is amazingly efficient.)


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]Mareshal[/eluser]
I've corrected my last post, because I wrote "ms" instead of "s".

Thanks for such detailed explanation. Anyway, DMZ is much faster than Doctrine 1.2 which has an average of 3.5s. Good work


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]OverZealous[/eluser]
[quote author="Mareshal" date="1269051053"]I've corrected my last post, because I wrote "ms" instead of "s".
[/quote]

I wondered about that! ;-)

Quote:Thanks for such detailed explanation. Anyway, DMZ is much faster than Doctrine 1.2 which has an average of 3.5s. Good work

That really amazes me. I would assume a dedicated ORM, which has a lot more flexibility than one tied to a second framework, would surely beat my little code :-P! That really goes to show how amazingly lightweight CodeIgniter is.

I can thank TheJim for helping on that front, though, as he really helped pare down some of the performance issues that plagued 1.6 and earlier.

Anyway, I wish you good luck working with DMZ!


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]Mareshal[/eluser]
I really want to work with DMZ but I have a 2 more questions:
1. For how much time will it me maintained and how many people are working on it ?
As a small comment, I've asked Doctrine manager to tell me how to upgrade from 1.2 to 2.0 and the answer was "YOU CAN'T", so all big companies using Doctrine 1.2 and want all bugfixes, will need to rewrite their code. whic was the answer. They changed a lot of methods and classes.
2. Is there any SVN/Mercurial version? You should really use a free SVN/Mercurial host, or something like that. Is very useful to submit bugs/suggestions.

Of course, there's no need to answer if you don't want. I am just curious to see how reliable is DMZ for my future projects.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]OverZealous[/eluser]
The short answer won't make you happy: I'm the only developer. For the foreseeable future, this won't change, although I accept suggestions and patches.

I do maintain it in an SVN repository, but it is privately hosted. I'm thinking about migrating to mercurial - but that benefit is for me, not necessarily to open it up more. I'm kind of the DMZ dictator, and I don't want turn this into a full-time job just verifying check-ins, etc. Smile

However, the good news is that everything that is important for developing DMZ is included in the download. It is ridiculously open-licensed, so anyone can take it copy it, modify it, resell it, or whatever. The only thing is that I retain copyright over the phrase "OverZealous", the DMZ logo, and there are some less-openly licensed graphics in the sample application.

I use DMZ exclusively in my own application (ZestyJobs), and will maintain it as long as I am able to. The only thing I've cut back on is supporting the HTMLForm extension, because it was just too much code for me to maintain alongside DMZ.

As far as upgrades go: The only things I plan on changing between 1.X and the eventual 2.X are not so dramatic. I'm mostly planning on clearing out legacy code, possibly migrating some of the lesser-used functions to extensions, so they don't take up resources (and lines of code) if they aren't needed, and those sorts of changes. I also may re-format the entire code base, because I personally don't like having the braces on their own line (I'm a Java guy originally). :-P

There will be an upgrade path, and it should be fairly painless. The majority of upgrade hurdles so far have affected developers who needed, for one reason or another, to access non-API methods, or manipulate undocumented internal properties.

One thing that might change that is how much work is needed to support CodeIgniter 2.0. If CI 2.0 requires a significant rewrite, I may use DMZ 2.0 as a clean break. However, as long as I've switched to Hg by then, I should be able to support both the 1.x and 2.x lines simultaneously for a while.

Finally, I most likely won't be supporting CodeIgniter 2.0 until it is released. It just isn't high on my priority list.

Sheesh, I'm extra loquacious today. :lol:


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]Mareshal[/eluser]
My turn now:
Maybe you don't believe me, but I am more than happy now. A one man work is better than a team sometimes. On the entire project is ONLY your coding style and standards, comments and so on. The "How many people" question was a small trick ;-)

Btw, are there any major bugs?

CodeIgniter won't change too much on 2.0 version I think. Most of the changes are already made.

offtopic: Java guy Tongue ? I put the first brace on the same line with the function/method, not like C/C++. Actually I am a student, and at university I learn c/c++/c# , now I am programming microcontrollers using C , but honestly I learned C++ from PHP. In CI I understood what's the role of __construct, classes, OOP and many other things, even if teachers explained us, was hard. I put much much more effort learning PHP/CI/SQL than c++.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-19-2010

[eluser]Mareshal[/eluser]
Another problem now, I think I am too tired now, but I'll post it.

Code:
function add(){
        $u = new User();
            $u->username = $this->input->post('username');
            $u->password = "pass";
            $u->first_name = "first_name";
            $u->last_name = "last_name";
            //echo $u->error->string;
        $u->save();
        
        $return['err'] = $u->error->string;
                
        if(!empty($u->error->string))
            $this->load->view('form', $return);
        else    
            echo "Added";
    }

I have a form and when I click submit I want to show the error. This works, but is not good, because UPDATE is made before testing the values. another way?