Re: Messy messy messy code

2006-08-24 Thread Doug Brown
Charles,

As far as orginization goes, I really have not seen much that is as
organized as fuesbox. It is not a object oriented process as much as a
method of reusing your code to your benefit. I will not go into alot of the
ins and outs, but will refer you to the site for that. Best of luck

http://www.fusebox.org



- Original Message - 
From: "Charles Sheehan-Miles" <[EMAIL PROTECTED]>
To: "CF-Talk" 
Sent: Thursday, August 24, 2006 7:15 AM
Subject: Messy messy messy code


> Hi all,
>
> I¹m a relatively new coldfusion programmer (if I can call myself that)
and
> I¹ve been working on an application for about two years now which hosts
> multiple websites under the same code base.  The particular website is
> determined by the host header name, and it works, so far as it goes.
>
> However, the app has grown dramatically, with the introduction of a lot of
> new features, to the point where maintaining the code is a terrible
> struggle.  Currently it has about 500 templates, with snaky, messy code
that
> leads here and there, and whenever I introduce a change or fix it breaks
> something else.  Very procedural, etc, with something in excess of 100,000
> lines of code.
>
> I came to the conclusion that putting together the new version, I¹m
> rewriting it from the ground up, using components as much as possible, but
> I¹m new to thinking in object oriented terms, so I was hoping to bounce my
> thinking off the list.  In particular, I want to make the various
functions
> as portable as possible, so I can reuse them wherever possible, and so I
can
> routinely introduce new features.  I¹m also concerned about performance <
> with some of most recent changes to the app, a few of the hosted sites
have
> taken an exponential leap in traffic (one of the sites is now drawing >
20k
> users/100,000 page views per day).
>
> There¹s a relatively small set of data, including the details of a
> particular organization, their formatting options, stylesheets choices,
> etc., which almost never change.  My intent was to place those in an
> application scoped cfc.
>
> In the past, I¹ve maintained user data in a members table, with associated
> tables for custom fields (defined by the customer), donation histories,
> online profiles, uploaded photos, etc.  This was all keyed off client
> variables, so logins were persistent.  I¹m thinking to set up a session
> scoped cfc to retrieve all of this data when someone visits or logs into
the
> site.  New visitors, or those not logged in, would have null values here
> until they logged in or registered.  Does it make sense to instantiate
this
> object (call it member.cfc) in application cfm?  I want to make sure the
> values in this are available throughout the application.  I¹m not sure
what
> kind of gotchas there are on session scoped components, though I¹ve been
> doing a lot of reading on the topic.
>
> There¹s a set of data which changes on a daily basis < database of
> congressional contacts, phone numbers, faxes, etc., staffers, etc.  Does
it
> make sense to persist something like this in a component?  The key factor
is
> that when a website visitor visits a page, the data is personalized < for
> example, if we have their zip code, the app determines who their
> representatives in Congress are and how they voted on specific
legislation.
> I¹m inclined to create the object in the application scope, then call the
> various functions passing them the values for the members.
>
> The final set of data is the website content, which typically changes very
> frequently, as website visitors post blogs and comments in addition to the
> customer posted articles.  Currently I cache most of these queries for
time
> periods between 2 and 10 minutes to reduce load on the server.  I¹m not
sure
> of the impact of encapsulating all of this data into a persistent CFC.  Do
> caching rules still apply?  For example, if I have a function
³listarticles²
> in a persistent component, can I cache that query inside the CFC so that I
> don¹t impact the database more than currently? In most of these cases, I
> don¹t want the data to be around for the life of the object, both because
it
> changes, and because there are tens of thousands of articles and blogs and
I
> don¹t want to crush my web server.
>
> I hope all these apparently newbee questions aren¹t too vague.  I¹m still
> getting a handle on how to best do this, and wanted to hear some thoughts
> from some of the folks here who are clearly more experienced at this.
>
> Finally < as I recode and test this, I¹m wondering if there are any good
> tools out there which can give a view of what is going on inside the web
> server in terms of persistent component < how much memory they are using,
&g

Re: Messy messy messy code

2006-08-24 Thread Jeff Guillaume
I'm just coming out of a year's worth of development on a very similar project, 
and let me tell you... LESSONS LEARNED.

Do not, do not, do not, rely on ColdFusion for heavily object-oriented CFCs 
that store their own data (in the CFC itself).  It's just not ready.  Don't get 
me wrong, I'm not talking about reasonable OO, but we had some consultants who 
were creating CFCs like pure Java classes (with lots of inheritance and 
override functions). After we added just one real customer, the server crashed 
hard (the pages took way too long to load, the memory added up and threads ran 
out).

That said, we have since revamped a lot of the architecture and now the site 
flies.  I would recommend:

Store as many reusable CFCs as possible in the application scope, so long as 
they don't hold any per-request data.  For your visitor tracking, I would 
suggest one CFC in the application scope that just manipulates session data.  
DON'T create and store a CFC for every visitor in session; it's a waste of 
memory.

Cache as many queries as possible using cachedwithin.  Caching queries is, 
consistently, in many different projects, by far the biggest performance 
improvement in CF I've ever encountered.  Be reasonable and don't cache stuff 
just for the sake of it, though. Caching articles for a few minutes is fine (I 
only do 30 seconds on HPANA.com). I use an application-scoped CFC to grab 
news/article content and query cache them as needed.

For your congressional database, I'd say (depending on how many rows it is) 
consider query caching the whole thing for up to 24 hours. Then use 
query-of-queries when you want to access it on a per-ZIP Code basis.

A good way to look at memory is to turn on the JVM's garbage collection 
debugging output.  You'll see from a bird's eye view how the memory grows with 
each request and how much garbage collection the JVM has to do when the time 
comes.  All of this impacts performance in the end.

It sounds like you already know most of what you have to do, and have the 
knowledge and research ability to figure out the rest.  Good job!


---
Jeff Guillaume
Kazoomis Online Media
http://www.kazoomis.com

~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250873
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: Messy messy messy code

2006-08-24 Thread Neil Middleton
I'm assuming here, you mean you're not going to put the data into the CFC?
Databases exist for a very good reason.

On 8/24/06, Charles Sheehan-Miles <[EMAIL PROTECTED]> wrote:
>
>
> There¹s a relatively small set of data, including the details of a
> particular organization, their formatting options, stylesheets choices,
> etc., which almost never change.  My intent was to place those in an
> application scoped cfc.



-- 
Neil Middleton

Visit feed-squirrel.com


~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250870
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: Messy messy messy code

2006-08-24 Thread Steve Brownlee
Charles:

Sounds like you have a year's worth of work here.  Good luck! I'm working on 
the assumption that you're using CFMX 6.1 or 7+

I¹m thinking to set up a session scoped cfc to retrieve all of this data when 
someone visits or logs into the site.  New visitors, or those not logged in, 
would have null values here until they logged in or registered.  Does it make 
sense to instantiate this object (call it member.cfc) in application cfm?
>> Yes, that's a good place to instantiate it.  In addition, if you're starting 
>> from scratch, use the Application.cfc onSessionStart() event instead of 
>> using Application.cfm

There's a set of data which changes on a daily basis database of congressional 
contacts, phone numbers, faxes, etc., staffers, etc.  Does it make sense to 
persist something like this in a component?
>> Well, you can't persist something in a component, per se, but you can 
>> persist the data in the application scope (in which the component can be 
>> stored)

Currently I cache most of these queries for time periods between 2 and 10 
minutes to reduce load on the server.  I¹m not sure of the impact of 
encapsulating all of this data into a persistent CFC.  Do caching rules still 
apply?
>> Yes

For example, if I have a function ³listarticles² in a persistent component, can 
I cache that query inside the CFC so that I don¹t impact the database more than 
currently?
>> Yes

In most of these cases, I don¹t want the data to be around for the life of the 
object, both because it changes, and because there are tens of thousands of 
articles and blogs and I don¹t want to crush my web server.
>> If that's the case, then you should avoid caching those queries unless you 
>> test it thoroughly and are sure your server has enough memory to store them. 
>>  Instead focus on optimizing your database indices and query management; 
>> that is, if you don't need to extract 10,000 records for a particular 
>> request, then don't, even if you think you'll need them soon.

Finally as I recode and test this, I¹m wondering if there are any good tools 
out there which can give a view of what is going on inside the web server in 
terms of persistent component how much memory they are using.
>> Unfortunately, no.  You can monitor your memory usage during specific tasks 
>> and then make an educated deduction on how that code performs.  As long as 
>> you isolate your test case enough, this is a reaasonably efficient process.


Steve Brownlee
http://www.fusioncube.net/



~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250867
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Messy messy messy code

2006-08-24 Thread Charles Sheehan-Miles
Hi all,

I¹m a relatively new coldfusion programmer (if I can call myself that)  and
I¹ve been working on an application for about two years now which hosts
multiple websites under the same code base.  The particular website is
determined by the host header name, and it works, so far as it goes.

However, the app has grown dramatically, with the introduction of a lot of
new features, to the point where maintaining the code is a terrible
struggle.  Currently it has about 500 templates, with snaky, messy code that
leads here and there, and whenever I introduce a change or fix it breaks
something else.  Very procedural, etc, with something in excess of 100,000
lines of code.  

I came to the conclusion that putting together the new version, I¹m
rewriting it from the ground up, using components as much as possible, but
I¹m new to thinking in object oriented terms, so I was hoping to bounce my
thinking off the list.  In particular, I want to make the various functions
as portable as possible, so I can reuse them wherever possible, and so I can
routinely introduce new features.  I¹m also concerned about performance ‹
with some of most recent changes to the app, a few of the hosted sites have
taken an exponential leap in traffic (one of the sites is now drawing > 20k
users/100,000 page views per day).

There¹s a relatively small set of data, including the details of a
particular organization, their formatting options, stylesheets choices,
etc., which almost never change.  My intent was to place those in an
application scoped cfc.

In the past, I¹ve maintained user data in a members table, with associated
tables for custom fields (defined by the customer), donation histories,
online profiles, uploaded photos, etc.  This was all keyed off client
variables, so logins were persistent.  I¹m thinking to set up a session
scoped cfc to retrieve all of this data when someone visits or logs into the
site.  New visitors, or those not logged in, would have null values here
until they logged in or registered.  Does it make sense to instantiate this
object (call it member.cfc) in application cfm?  I want to make sure the
values in this are available throughout the application.  I¹m not sure what
kind of gotchas there are on session scoped components, though I¹ve been
doing a lot of reading on the topic.

There¹s a set of data which changes on a daily basis ‹ database of
congressional contacts, phone numbers, faxes, etc., staffers, etc.  Does it
make sense to persist something like this in a component?  The key factor is
that when a website visitor visits a page, the data is personalized ‹ for
example, if we have their zip code, the app determines who their
representatives in Congress are and how they voted on specific legislation.
I¹m inclined to create the object in the application scope, then call the
various functions passing them the values for the members.

The final set of data is the website content, which typically changes very
frequently, as website visitors post blogs and comments in addition to the
customer posted articles.  Currently I cache most of these queries for time
periods between 2 and 10 minutes to reduce load on the server.  I¹m not sure
of the impact of encapsulating all of this data into a persistent CFC.  Do
caching rules still apply?  For example, if I have a function ³listarticles²
in a persistent component, can I cache that query inside the CFC so that I
don¹t impact the database more than currently? In most of these cases, I
don¹t want the data to be around for the life of the object, both because it
changes, and because there are tens of thousands of articles and blogs and I
don¹t want to crush my web server.

I hope all these apparently newbee questions aren¹t too vague.  I¹m still
getting a handle on how to best do this, and wanted to hear some thoughts
from some of the folks here who are clearly more experienced at this.

Finally ‹ as I recode and test this, I¹m wondering if there are any good
tools out there which can give a view of what is going on inside the web
server in terms of persistent component ‹ how much memory they are using,
etc.  I¹ve used FusionReactor, but that seems to only address currently
running requests.

Thanks,

Charles

 












~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250847
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4