<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Demonen&apos;s Rewrite</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/demonen/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/demonen//910</id>
    <updated>2011-11-15T07:15:48Z</updated>
    <subtitle>mod_perl2 to modern Perl in 39274 easy steps</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Never mind!</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/2011/11/never-mind.html" />
    <id>tag:blogs.perl.org,2011:/users/demonen//910.2444</id>

    <published>2011-11-15T07:11:05Z</published>
    <updated>2011-11-15T07:15:48Z</updated>

    <summary>The rewrite was cancelled. This is in part because of cost, and also because the client involved are, in the long term, including the functionality in their SAP &quot;solution&quot;. I could rant for several megabytes about how this is a...</summary>
    <author>
        <name>Demonen</name>
        <uri>http://fredrikvold.info/</uri>
    </author>
    
        <category term="Babble" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Politics" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="irrelephant" label="irrelephant" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sap" label="SAP" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="unperl" label="un-perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/demonen/">
        <![CDATA[<p>The rewrite was cancelled.</p>

<p>This is in part because of cost, and also because the client involved are, in the long term, including the functionality in their SAP "solution".</p>

<p>I could rant for several megabytes about how this is a silly desicion, but it was made so far above my head I can't even see it from here.  Seems like that's always the case when SAP is involved.</p>

<p>So, after spending roughly €20.000 on something it's being scrapped, and some SAP consultant will implement it (sort of, anyway) in their way, and bill €1.000.000.  Yep, makes perfect business sense for all involved.</p>

<p>Aaanyway, never mind this blog.  It's not relevant.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Can I just do my job?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/2011/10/can-i-just-do-my-job.html" />
    <id>tag:blogs.perl.org,2011:/users/demonen//910.2286</id>

    <published>2011-10-13T06:16:41Z</published>
    <updated>2011-10-13T06:30:45Z</updated>

    <summary>One thing I&apos;ve learned over the last few months is that nothing happens quickly or easily in a company of over 125.000 people.My rewrite effort has been bogged down in security certifications and other time-consuming stuff, so I&apos;ve been unable...</summary>
    <author>
        <name>Demonen</name>
        <uri>http://fredrikvold.info/</uri>
    </author>
    
        <category term="Babble" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Politics" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="politics" label="politics" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="productivity" label="productivity" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/demonen/">
        <![CDATA[<p>One thing I've learned over the last few months is that nothing happens quickly or easily in a company of over 125.000 people.</p><p>My rewrite effort has been bogged down in security certifications and other time-consuming stuff, so I've been unable to sit down and do much actual code.<br />In stead, I've been reading&nbsp;<a href="http://onyxneon.com/books/modern_perl/">Modern Perl</a>&nbsp;again, and trying to wrap my head around&nbsp;<a href="https://www.pcisecuritystandards.org/">PCI security standards compliance</a>, and reading a whole stack of blogs and books about Perl (thanks,&nbsp;<a href="http://ironman.enlightenedperl.org/">guys</a>!).</p><div>I can't say I understood anything beyond the basics. &nbsp;"Stop people that don't need access to credit cards from getting at them." &nbsp;Where I'm from, we don't need a 9001 page document to say that, but I guess they want to cover every base.</div><div><br /></div><div>I'm just wondering how much these endless phone conferences, meetings and delays have cost.</div><div>Not just of my time, but several people that make twice as much as me, and a couple that make at least five times as much.</div><div>What did we end up with in the end? &nbsp;Pretty much the same thing proposed back in May.</div><div><br /></div><div>The difference is, that it's now been vatted by Security, and approved. I see why that was needed, but at the same time I don't understand why I was involved. &nbsp;I have a good grasp of security on the code level, such as never ever trusting user input, and all that, but I haven't contributed much to the whole security discussion.</div><div><br /></div><div>On top of that, I can't really write much code until the development model is approved, or I'd risk having to rewrite it all every other week.</div><div>I'm just very glad I've had so much to read and do outside writing code so I haven't degraded into silliness, but I can't help thinking this has been rather unproductive on the whole.</div><div><br /></div><div>Can I just do my job now, please?</div>]]>
        
    </content>
</entry>

<entry>
    <title>Catalyst? Really?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/2011/08/catalyst-really.html" />
    <id>tag:blogs.perl.org,2011:/users/demonen//910.2142</id>

    <published>2011-08-29T05:33:41Z</published>
    <updated>2011-08-29T06:01:40Z</updated>

    <summary>I&apos;ve been so busy doing Actual Work that I&apos;ve forgotten to write about doing it! Now that a lot of the modules I&apos;ll be using are more or less in place, including my new centralized security where &quot;everything&quot; will go...</summary>
    <author>
        <name>Demonen</name>
        <uri>http://fredrikvold.info/</uri>
    </author>
    
        <category term="Choices" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="catalyst" label="catalyst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="websimple" label="web::simple" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/demonen/">
        <![CDATA[<p>I've been so busy doing Actual Work that I've forgotten to write about doing it!</p>

<p>Now that a lot of the modules I'll be using are more or less in place, including my new centralized security where "everything" will go to get permission to do "anything", it's time to start sowing the modified modules together in Catalyst.</p>

<p>Or is it?</p>

<p>I try to code by "Make a plan, and stick to it, unless it sucks."<br />
Figuring out if a solution sucks is part of that, so I've taken a long, hard look at my Catalyst choice here.</p>

<p>Did I really pick Catalyst because it's the best tool for the job, or because it's the weapon I had in my hip holster at the time?  Let's see what we're looking at here:</p>

<ul>
	<li>About 25-50 users per set-up, each set-up will have a separate VM in a separate physical location, and will not communicate with each other.</li>
	<li>Roughly 0% of the data will be cached.  Everything is "fresh" out of the database to the user, or it would not be given to the user.</li>
	<li>Performance is very important, but stability and maintainability is even more important.</li>
	<li>In the future, this might have to be maintained by people that don't actually know Perl that well.</li>
</ul>

<p>So, how does this mesh with my view of Catalyst?</p>

<ul>
	<li>Will easily handle thousands of users if Done Right.</li>
	<li>Caching and balancing is very easy to do.</li>
	<li>A little confusing to get into at first, but if maintained by a Perl-head it's the best thing ever for a web-app.</li>
</ul>

<p>Oh.  Well...  That doesn't look very good for Catalyst in this context, does it?<br />
What else is there, that will do this job in a way that might be a little simpler for my successors to maintain?</p>

<p>How about <a href="https://metacpan.org/module/Web::Simple">Web::Simple</a>?<br />
I've been playing with it sort of as a toy lately, and I've grown to like it a lot, but will it really work in my business application?</p>

<p>Yes it will, and it will work great!</p>

<p>What the application will be doing is mostly simple CRUD work, which will be handled by <a href="https://metacpan.org/module/DBIx::Class">DBIx:Class</a> and a bit of wand-waving there, in pretty much the same way no matter what framework I build it in.<br />
The really heavy stuff isn't done by the user-facing web script at all, but in a dedicated cron-run script, so for the heavy lifting it's irrelevant what web framework is used.</p>

<p>Then comes the <a href="http://thedailywtf.com/Articles/The_Brillant_Paula_Bean.aspx">brillant</a> part:  If done properly, it'll be easy to shift from <a href="https://metacpan.org/module/Web::Simple">Web::Simple</a> to <a href="https://metacpan.org/module/Catalyst">Catalyst</a> later.</p>

<p>Right, so now I'm not building a Catalyst app anyway, because I don't really need the heavy lifting Catalyst can do.</p>

<p>The great thing about this is that all I really need to re-do of the work that's already been done is to rewrite a few of the tests and search-and-replace "Catalyst" with "Web::Simple" in the documentation.  Seriously.<br />
</p>]]>
        
    </content>
</entry>

<entry>
    <title>Rebuilding the model</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/2011/07/rebuilding-the-model.html" />
    <id>tag:blogs.perl.org,2011:/users/demonen//910.1993</id>

    <published>2011-07-20T06:30:22Z</published>
    <updated>2011-07-20T09:35:46Z</updated>

    <summary>Yesterday I decided to stay with MySQL, but today I face something a little more creative: What should the data model look like? So far today I&apos;ve collected a list of all the information I would like to store, and...</summary>
    <author>
        <name>Demonen</name>
        <uri>http://fredrikvold.info/</uri>
    </author>
    
        <category term="Babble" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="databasedesign" label="Database design" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/demonen/">
        <![CDATA[<p>Yesterday <a href="http://blogs.perl.org/users/demonen/2011/07/to-switch-or-not-to-switch.html">I decided to stay with MySQL</a>, but today I face something a little more creative:  What should the data model look like?</p>

<p>So far today I've collected a list of all the information I would like to store, and marked out all the information that is currently stored.  It doesn't look like I have to add a lot of information, but I'm certainly changing how it's stored.<br />
In the current version of the application a whole lot of the information is stored in static configuration files.</p>

<p>For example, the concept of a "Morph Rule" is a configuration variable.<br />
So a case type is changed in accordance with a "Morph rule".<br />
When this was designed it was not clear how often these things would change or need tuning, so it was hard coded in a way that would make it very fast to load at start-up, and very easy to access while running, but very impractical for the application to change.<br />
Changes are currently done by manually editing .pm files.</p>

<p>This would have been fine if the changes were few and far between, but I find myself editing this "configuration" a whole lot more often than the design documentation of the application indicates necessary.  In the past, these things "never" changed, but this business is becoming more and more dynamic, and changes more and more frequent.<br />
Clearly, this has to be on-the-fly changeable by administrative users.  If they have to toss it across my desk every time there is a change I won't be able to do much else.</p>

<p>Another thing that's very wrong about the existing model is the lack of foreign keys anywhere.<br />
This is my doing of about a year and a half ago, and it shows my lack of experience with complex databases.  My reasoning behind it is that if something goes wrong it's a lot less complicated to untangle the mess if you're not constrained by a bunch of foreign keys.  Since then it has become clear to me that in such an emergency you can simply suspend foreign key enforcement.<br />
Oh, the sins of the past...  I'm just glad I have a chance to undo them.  With what I've learned since then I'm sure I can build a better model.</p>

<p>MySQL (or variant), InnoDB, and foreign keys, all supported by some nice DBIx::Class as model for a quick and snappy Catalyst application.<br />
Yep, this is starting to taste like a real project now.<br />
</p>]]>
        
    </content>
</entry>

<entry>
    <title>To switch or not to switch - The MySQL Question</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/2011/07/to-switch-or-not-to-switch.html" />
    <id>tag:blogs.perl.org,2011:/users/demonen//910.1991</id>

    <published>2011-07-19T05:46:39Z</published>
    <updated>2011-07-19T07:46:21Z</updated>

    <summary>Before I let my enthusiasm overpower me and jump into this rewrite with all it&apos;s worth, I have to take a long and hard look at what technologies are being used, and what I want to replace them with. Swapping...</summary>
    <author>
        <name>Demonen</name>
        <uri>http://fredrikvold.info/</uri>
    </author>
    
        <category term="Choices" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="mysql" label="MySQL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="postgresql" label="PostgreSQL" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/demonen/">
        <![CDATA[<p>Before I let my enthusiasm overpower me and jump into this rewrite with all it's worth, I have to take a long and hard look at what technologies are being used, and what I want to replace them with.</p>

<p>Swapping out  <a href="http://metacpan.org/module/Class::DBI">Class::DBI</a> with  <a href="http://metacpan.org/module/DBIx::Class">DBIx::Class</a> is an easy choice, and I'll get back to that in a later post, but what of the engine behind it?</p>

<p>Currently, the whole thing is built on MySQL, but during the lifespan of this fairly complex CRM application I have seen some of the limitations of MySQL up close.<br />
A lot of my contacts and friends also insist that while MySQL is fine for a website or any simple CRUD operations, it will let you down when it comes to more complex queries.</p>

<p>Rumor has it that these problems are both in performance and dependability, and while it might have been simple user error, I have seen both.<br />
Keep in mind, however, that I am no DBA.  What indexing my databases currently have I have gotten help from friends and colleges to build, or they were already built, and I inherited them.</p>

<p>What I think, however, is that the optimum choice of database is largely dependent on the use case.<br />
For our statistics needs, for example, there is a lot of <em>COUNT</em> usage, and anyone worth their salt knows that PostgreSQL and most (all?) other <a href="http://en.wikipedia.org/wiki/Multiversion_concurrency_control">MVCC</a>-implementing database engines, even InnoDB for MySQL, will <em>COUNT</em> rather slowly.</p>

<p>A splash of googling turned up <a href="http://blog.charcoalphile.com/2007/12/12/postgresql-count-workaround/">a PGSQL COUNT(*) workaround</a>.<br />
I must say, that's pretty good.  The total number of rows in the database, however, is useless to me.<br />
I need stuff like...<br />
<code>SELECT COUNT(DISTINCT(`caseID`)) FROM events WHERE userID = 31;</code><br />
...to determine how many unique cases user 32 has logged events for.</p>

<p>Alright, so I update the user record every time a case is assigned, to reflect the "ownership count" for the user that lost it and the user that gained it.  Right?<br />
<code>SELECT COUNT(DISTINCT(`caseID`)) FROM events WHERE userID = 31 AND loggedTime > NOW() - INTERVAL 30 DAY;</code><br />
...Okay, now what?  I need to know how many unique cases user 31 has logged events for in the last 30 days.  Suddenly, it becomes very complex to keep updated.  So complex, in fact, that it's better for overall performance if I just leave it with the straight-up <em>COUNT</em> syntax with no further hooplah.</p>

<p>In the end, it comes down to this:  Where do I need the speed?</p>

<p>Both me and the people who will be using the statistics on a daily basis are fine with the statistics taking a few seconds to load.  That's not where the performance is needed.<br />
Where it is needed, however, is in the so-called Morphing, where our business rules are applied.  It's also needed in Case Selection, where the cases are prioritized and the one that comes up on top is handed to the first available agent.</p>

<p>So, yeah, <em>COUNT</em> is relatively slow, but I won't be using that as much as long, complicated and confusing <em>SELECT</em> that don't have any <em>COUNT</em> in them at all.<br />
It's these 50-line <em>SELECT</em>s I have to worry about.  The <em>WHERE</em>wolves.</p>

<p>When it comes to these beasts, I set out to try and find dirt on each database engine.  The problem with doing this kind of research is that anything I might find might be very much out of date.  A major problem with any DB engine could be fixed in the latest release, so I need the data as fresh as I can get it.</p>

<p>How about <a href="http://www.randombugs.com/linux/mysql-postgresql-benchmarks.html">June 2009</a>?  Since that article, PostgreSQL has advanced from 8.3.7 to 9.0.4 and MySQL from 5.1.30 to 5.5.14.<br />
Obsolete data!</p>

<p>After over an hour just searching for data and even trying to run some benchmarks of my own, I spoke to a coworker on the subject.  He's not doing software development for the company, but he runs a website with thousands and thousands of hits per day in his spare time.  It runs MySQL.<br />
He made me realize one major upside to MySQL:  People know MySQL!</p>

<p>I won't be around to maintain this application for ever, and poking around the company a little reveals a healthy heap of MySQL people, but only the occasional "Yeah, I've used Postgres once".</p>

<p>So, it turns out that this decision won't be about dependability or performance at all.  It will be about maintainability down the line, and about what people out there know how to use.<br />
With the performance so seemingly close, and dependability reportedly being so much improved for InnoDB in MySQL in later versions, it seems we're staying with it.</p>

<p>I just never even thought of this reason to do so.</p>

<p>Thanks, Tom Erik.  Your perspective was very valuable to me.</p>]]>
        
    </content>
</entry>

<entry>
    <title>And so it begins</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/demonen/2011/07/and-so-it-begins.html" />
    <id>tag:blogs.perl.org,2011:/users/demonen//910.1983</id>

    <published>2011-07-18T05:01:00Z</published>
    <updated>2011-07-18T05:10:33Z</updated>

    <summary>So, yeah, here I am. I&apos;m about to embark on a project to rewrite a mod_perl2 application to Catalyst. I promised mst I would blog about it, or otherwise make the process known, so that others might follow my example....</summary>
    <author>
        <name>Demonen</name>
        <uri>http://fredrikvold.info/</uri>
    </author>
    
        <category term="Babble" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="catalyst" label="catalyst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mod_perl" label="mod_perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mst" label="mst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/demonen/">
        <![CDATA[<p>So, yeah, here I am.</p>

<p>I'm about to embark on a project to rewrite a mod_perl2 application to Catalyst.<br />
I promised <a href="http://www.shadowcat.co.uk/blog/matt-s-trout/">mst</a> I would blog about it, or otherwise make the process known, so that others might follow my example.</p>

<p>Sure, I'll do that, but is it really a good idea to follow in my footsteps?<br />
I'll leave that up to you, my reader.  I obviously have at least ONE reader, as you're currently reading this.  Right?</p>

<p>I can't share any of the source code in the larger context, since I don't own it.  My employer would probably fire me outright if I shared the proprietary software, and I'll even do my best to keep my employers name out of this.  This is about the process of rewriting, not about <em>my job</em> in general.<br />
I also won't go into the old software too much, except where it's relevant for the rewrite, and I won't comment on the choices made when it was written or anything of the sort.  This is about modernizing, not about dredging up the past.</p>

<p>Let's just hope I remember to update this as frequently as I want!</p>]]>
        
    </content>
</entry>

</feed>
