Beta

Slashdot: News for Nerds

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Load List Values for Improved Efficiency

Hemos posted more than 9 years ago | from the leaner-and-meaner dept.

Databases 207

An anonymous reader writes "Reduce the number of database hits and improve your Web application's efficiency when you load common shared list values only once. In this code-filled article, learn to load the values for drop-down lists when your Web application starts and then to share these loaded list values among all the users of your application."

cancel ×

207 comments

I GOT A GREASED UP YODA DOLL SHOVED UP MY ASS! (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#12405714)

GO LINUX!

You know what's great (3, Insightful)

Anonymous Coward | more than 9 years ago | (#12405715)

When telling us there's code... TELLING US WHAT LANGUAGE. It's Java.

re: (0)

Anonymous Coward | more than 9 years ago | (#12405810)

What? and give us all the details so we don't have to rtfa.
Like we need that stuff anyway to make a post!! neh eh!!! *pokes out tongue*

Re:You know what's great (0)

Anonymous Coward | more than 9 years ago | (#12405811)

How is this 'news for nerds'? I mean, were all pretty intelligent people on this site... Surely the tech-savvy readership of slashdot don't need to have basic, obvious computer-science 101 techniques like 'caching' explained to us - do we?


I'd like to point out that one of the problems with this approach is that the cache could become inconsistant if someone updates the database after you have populated the menu. Worth thinking about for all you 31337 h4x0rs out there...


Re:You know what's great (1)

tomhudson (43916) | more than 9 years ago | (#12406057)

The application loads all drop-down list items at the start of the user session and uses them for the entire session. The drop-down list items are stored in the session. In a user session, the number of database hits is constant and the database hit count increases proportionally to the number of sessions.
I'd like to point out that one of the problems with this approach is that the cache could become inconsistant if someone updates the database after you have populated the menu. Worth thinking about for all you 31337 h4x0rs out there...
Storing it in the session to fake "persistence" is lame. If its something that's not going to change over the time the person is using it, store it in a file, and include the file in the equiv. of their home dir (you DO give your users their own home dir, to reduce database accesses, don't you?). The added benefit is, if they change the values, you can store the new values in the same file, and you also have persistence between sessions. If its something that all users of that app will be using, then storing it in a common file is also more intelligent.

Right tool for the right job - not every piece of info you serve needs to be stored in a db.

Re:You know what's great (1)

ahmusch (777177) | more than 9 years ago | (#12406378)

I respectfully disagree with your statement, although likely not the intent. Every piece of info you serve should be stored in a database, but not every piece of info you serve needs to be served from a database every single time.

Re:You know what's great (1)

eyeye (653962) | more than 9 years ago | (#12405817)

Reams of java too, though I guess much of that is not directly involved in the caching.

In persistent perl:

{ #note extra scope
my @dropdowndata;
sub whatever{
#call sub/method unless you already have the cached version.
@dropdowndata ||= load_dropdown_data();
}
}

Re:You know what's great (0)

Anonymous Coward | more than 9 years ago | (#12406065)

Re your sig.. do you have any reliable evidence for that 100,000 figure?

Re:You know what's great (1, Insightful)

Anonymous Coward | more than 9 years ago | (#12405840)

I don't care what language was used. It could have been VB. What matter to me is the concepts.

Should I agree with the concept, it's then up to me to implement the solution in my favorite language.

Re:You know what's great (1)

Hament (880657) | more than 9 years ago | (#12405846)

yes please is it java? hament verma http://linkedin.blogspot.com/>

Re:You know what's great (2, Funny)

Anonymous Coward | more than 9 years ago | (#12405924)

Thank you so much for telling me this. I would have been completely stuck if you hadn't, I had missed the java headers right at the top of the first bit of code and thought it was ZX80 assembler.

Too complex for VBS (1)

AwaxSlashdot (600672) | more than 9 years ago | (#12405999)

Well, the complexity of the problem made me think it would be VBS. This is the kind of example you can found in 'Advanced VBS' (or even Expert level).
Oh wait, you were talking about coding language ...

Re:You know what's great (0, Flamebait)

m4dd00d (880223) | more than 9 years ago | (#12406030)

Java's way to sloow for fast database access anyway. What's the point in using it?

Re:Hungarian & long var names (1, Informative)

Anonymous Coward | more than 9 years ago | (#12406165)

Vector obj_VectorOptions = new Vector();

What's with the mixing of Hungarian and long variable names?

I've been programming Java for 8 months and even I can tell this is a waste of space.

Re:You know what's great (0)

Anonymous Coward | more than 9 years ago | (#12406245)

While we're all savaging this poor bastard, how about a mention of his superb error-handling and logging mechanism?
try { ListValuesLoader listValues = new ListValuesLoader(); listValues.createValidValuesList(); } catch(Exception e){ System.out.println("There is a problem in getting the list values"); }
Ah, yes, good ol' standard out ...

First post (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#12405716)

First post

Frist! (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#12405720)

Frist

Changes to the lists? (5, Insightful)

saundo (312306) | more than 9 years ago | (#12405722)

Interesting article, but preloading those values will invariably lead to out of sync conditions when the backend changes. Nothing mentioned in the text as to how to cater for that eventuality.

Re:Changes to the lists? (0)

Anonymous Coward | more than 9 years ago | (#12405733)

When the mostly static list values in the back-end database get updated you restart the app server.

Re:Changes to the lists? (3, Informative)

AndrewStephens (815287) | more than 9 years ago | (#12405754)

An excellent point, the article assumes that the data will not change very often, if at all. However, if the list data doesn't change very often then there is little point storing it in the database in the first place.

Not to say that the article was actually bad or anything, its just a little light on when you would want to use this, and what some of the problems with this approach are.

Re:Changes to the lists? (1, Insightful)

Anonymous Coward | more than 9 years ago | (#12405779)

"However, if the list data doesn't change very often then there is little point storing it in the database in the first place."

Really? What about articles on the web or posts here in Slashdot? They almost never change and are usually stored in the database.

Re:Changes to the lists? (1)

AndrewStephens (815287) | more than 9 years ago | (#12405821)

"However, if the list data doesn't change very often then there is little point storing it in the database in the first place."
Really? What about articles on the web or posts here in Slashdot? They almost never change and are usually stored in the database.
It doesn't matter that the content of the articles doesn't change, the whole "list of articles" keeps growing as new articles get posted, hence the need for a database.

What this article is about is data that doesn't change very ofter (or at all). In slashdot terms, this would be the list of moderator categories (insightful, funny, troll, etc). This list changes very infrequently, and could easily be cached (as in the article), or even hard-coded save a database query (I have no idea how it is actually implemented).

Re:Changes to the lists? (3, Insightful)

Anonymous Luddite (808273) | more than 9 years ago | (#12406201)

>> posts here in Slashdot?

Apples and oranges.

You're talking about adding items (posts) to a recordset (slashdot thread). The items are static but the recordset is not. It changes frequently.

The caching they're talking about involves a recordset that seldom changes, and would therefore be suited to storage outside a database and rebuilt as it changes - IE one trip to the database per change rather than one trip per view. This wouldn't make sense with something like a slashdot thread where records are added non-stop...

Re:Changes to the lists? (1)

Cobralisk (666114) | more than 9 years ago | (#12406006)

Maintaining separation of code, presentation, and data would require a place to store the list choices. Logically, this would be in the database, where you keep the rest of your data, which is dependent on the list choices. You cache the data since it is basically static. This approach can be more efficient than repetitive redundant database lookups, and more elegant than hard coding the choices into the script, or the <html>.

Re:Changes to the lists? (1, Informative)

Anonymous Coward | more than 9 years ago | (#12406258)

Before making assumptions about your database, check with the DBA or research the architecture of the database. Many DBMS's will cache frequently accessed static query results.

Re:Changes to the lists? (2, Informative)

ahmusch (777177) | more than 9 years ago | (#12406318)

Of course, the article leaves one key point unsaid but implied...

Understand the nature of your data.

In any system, there's basically three kinds of data:

-- Static: This is the stuff that changes at a glacial pace, such as state codes, currency codes, and so forth. (for bonus points, put all the static code/description values in a single table with a type identifier for an even larger performance increase at the cost of slightly more complicated code.)

-- Configuration: This is the data that drives the logic of the application. (Go ahead, put it all in code. Good luck with the maintenance.)

-- Data: The actual records that you process or interrogate at some level to do something.

If the JDBC monkeys don't understand the nature of the data at this fundamental level, then telling them to cache data is a recipe for concurrency and consistency nightmares. Not because they mean to, but because they don't know any better.

Caching the static data is probably safe, but the configuration data is only *somewhat* safe to cache. It's too expensive to continually round-trip for everything, so what my project has done is implement a warm-boot process. For every transactional record it attempts to process, it checks a warm-boot status table. If the time has changed, the app flushes and repopulates its caches of both static and configuration data. Sure, it's a little kludgy, but it gives us at least parts of the best of both worlds.

Re:Changes to the lists? (2, Interesting)

Flibz (716178) | more than 9 years ago | (#12405807)

I find that something that helps there, particularly if different users have diferent data for the list is to use javascript.

Basically, create a session variable for the user (we'll call it cacheTimeStamp) with the current date/time to the hour (i.e. yymmddhh).

When the page with the drop-down list is called, check current timestamp. If it's expired, create a new javascript .js file & delete the old one.

Then, when the <script> tag is called, use thecacheTimeStamp value to ensure a current .js file is called and let the client browser handle the caching...

Re:Changes to the lists? (0)

Anonymous Coward | more than 9 years ago | (#12405926)

Why not be a tad smarter about it? Instead of some fixed timeout for cache data, have a quick query to find out the last time a dataset changed and use that to determine if your cached info is out of date.

Unless that's what you already meant . . . my reading skills are often lacking.

Re:Changes to the lists? (1)

Digital11 (152445) | more than 9 years ago | (#12405851)

If you were using .NET 2.0 you could use a database dependency cache model which checks to see if data has been updated every so often, and if it has it flushes its cache and reloads the data.

Granted, you could also write it in Java, just saying that its readily available in .Net.

Re:Changes to the lists? (1)

XMyth (266414) | more than 9 years ago | (#12405902)

That and even with .NET 1.0 the solution describe in the article is built-in as well. Application, Session, and Cache collections.

Re:Changes to the lists? (1)

zorander (85178) | more than 9 years ago | (#12405856)

class Category 'parent IS NULL')
end

before_save :invalidate_root_cache
def invalidate_root_cache
@@root_cache = nil
end
end

Being that that was a lot of java code, this is an example in rails. before_save marks a method that should be framework-invoked before commiting a change to the database on the categories table (which is introspected from the 'Category' class name, but can of course be overridden). This caches the category list and expires it whenever it may have changed.

This can of course be made much more elaborate. I'm sure that java code is doing more, being that there's so much of it. Is there a reason why a simpler solution to the problem is unfit? This sort of caching is safe and easy to implement across a system on common queries.

Of course, there's also memcached which provides the same effect without writing a line of code. Am I missing something?

Re:Changes to the lists? (1)

Cobralisk (666114) | more than 9 years ago | (#12406060)

Of course, there's also memcached which provides the same effect without writing a line of code. Am I missing something?

Most likely IBM programmers in India are paid by the line of code. In which case, you're missing everything.

Re:Changes to the lists? (1)

MemoryDragon (544441) | more than 9 years ago | (#12405925)

not necessarly, you just have to set an interceptor which is triggered once the values are edited and updated... very easy to to, either with direct db related interceptors, application events or aspects...

Huh? (5, Insightful)

Renegade Lisp (315687) | more than 9 years ago | (#12405727)

Sorry I don't get it. Of course, when you load your data from a cache in main memory, even from within the same address space, you are several orders of magnitude faster than if you make the trip to the database each time. And by several orders of magnitude I mean six to seven orders: you'll easily be a million times faster for a given operation. (A database roundtrip is on the order of tens of milliseconds, while a lookup in a Java hashtable takes mere nanoseconds on typical hardware.)

What's the point? Since when is Slashdot a forum for random tech tips (and not very thrilling ones at that)? Did IBM pay to get this posted? Is Slashdot trying to make fun of IBM by actually posting it?

Re:Huh? (3, Funny)

0x461FAB0BD7D2 (812236) | more than 9 years ago | (#12405769)

It's because of all the Adblock users out there that we get ads as stories now. The summary even reads like one. Or it's just a slow news day.

It all depends on how tight your tin foil hat is.

Re:Huh? (0)

Anonymous Coward | more than 9 years ago | (#12405775)

Slashdot is just trying to get the word out on simple techniques to help withstand the crushing impact of a slashdotting. (Something about it being part of their hours of community service, not sure what that's all about.)

Re:Huh? (1)

fedor (598123) | more than 9 years ago | (#12405997)

simple techniques!? IBMs examples are pieces of over-engineered bloatware....

why not just:

getValues()
{
if (list==null)
list=loadList();
return list;
}
??

Isn't that easier than writing XML-configuration files?

Re:Huh? (5, Insightful)

computational super (740265) | more than 9 years ago | (#12405914)

I think you're being FAR too polite here, sir. Feel free to drop in an occasional, "Are you f-ing kidding me with this drivel?" in your critique of this type of ridiculously simplistic and obvious article.

On the other hand, there's a good take-away here. If this "revolutionary technique" was so mind-bending to IBM consulting services, I know where I won't be spending my consulting dollars...

Re:Huh? (1)

Renegade Lisp (315687) | more than 9 years ago | (#12406228)

On the other hand, there's a good take-away here. If this "revolutionary technique" was so mind-bending to IBM consulting services, I know where I won't be spending my consulting dollars...

It's interesting though, that this kind of "revolutionary technique" can be indeed a step forward in the I-don't-know-how-many projects where developers aren't aware of these simple issues. I'm in the consulting business, I've seen them. For them, this kind of consultant might actually be worth the money, and there's nothing ridiculous about it. Some shops simply have no need to have the brightest and smartest developers in-house.

Where did you get that from? (1)

hrvatska (790627) | more than 9 years ago | (#12406313)

Where did anyone present this as a "Revolutionary technique"? I don't see that as being said or implied anywhere. It's a how to article for people who are new to Java, with a (nearly) complete end to end example. Should it have warranted an article in /.? Perhaps not, but your crticisms of IBM consulting services, based on a how to article for new Java developers, seems to be quite a leap.

From the 'duh' department... (0)

Anonymous Coward | more than 9 years ago | (#12405962)

Woah, you can cache objects in memory? You don't need to go to the remote database to get a list of states names? Holy crap!

Yes. (0)

Anonymous Coward | more than 9 years ago | (#12405984)

But, have you actually looked at the crap most open source projects turn out? (Certain ones are turning out incredibly high quality works of art; most, like slashcode, are crap.) I think this is actually a real hint to the majority of slashdot readers who are completely clueless.

Re:Huh? (1)

fedor (598123) | more than 9 years ago | (#12406010)

It's a joke... The article was written by Ali G... look at the picture at the end of the article.

Re:Huh? (1)

cablepokerface (718716) | more than 9 years ago | (#12406055)

Hahaha. You're right!

If only I had mod points.

Oblig. Simpsons Quote (4, Funny)

bigtallmofo (695287) | more than 9 years ago | (#12405729)

"And people, I can't stress this enough. Put your garbage in the garbage can."

"Garbage in the garbage can. Hmm. Makes sense."

Mod parent up! (1)

Renegade Lisp (315687) | more than 9 years ago | (#12405746)

No need to post anything else in this thread! ROTFL

Re:Oblig. Simpsons Quote (1)

Darth_Burrito (227272) | more than 9 years ago | (#12405963)

Heh, I once wrote a generic query caching system in .net and garbage collection was indeed a serious problem.

Slow news day? Christ. (5, Insightful)

Electroly (708000) | more than 9 years ago | (#12405730)

This just in! Caching frequently-used data yields performance improvements! Film at 11!

April Fools... (4, Funny)

Kr3m3Puff (413047) | more than 9 years ago | (#12405731)

Is this April First?

Wow, next an article about using "for" loops? The benefits of "bubble sort"? "Binary trees"?

Well duh! (3, Insightful)

AndrewStephens (815287) | more than 9 years ago | (#12405732)

Keeping frequently used data in static singletons, who would have thought it!
Seriously, this is probably good advice for someone just starting out programming, but I would expect anyone with any experience at all to know about this. Its hardly a revolutionary new technique.

Re:Well duh! (1)

computational super (740265) | more than 9 years ago | (#12405927)

Actually, I was pretty disappointed at the author's choice of singletons for the static data in this (painfully obvious) article... this is actually the sort of thing that ServletContext was designed for. Singletons always bother me because they're basically global variables, with all the problems that global variables bring.

Re:Well duh! (2, Insightful)

DaHat (247651) | more than 9 years ago | (#12406139)

Be careful with mentioning design patterns like Singletons, you may lose most of the spaghetti code programmers.

Done this for years (5, Insightful)

Ckwop (707653) | more than 9 years ago | (#12405734)

Well thank you captain obvious.. I've been doing this for years with ASP. Just load the contents of the listboxes into the Application object.

In ASP.NET you can even do cache invalidation when the database changes. Simply create an extended stored procedure that's fired when any of you update/insert producers run that write to the changed record ids to a Queue (using Microsoft's Messaging and Queuing service) then have a thread in the ASP.NET process that periodically check the queue for new messages and clear the values that have changed out of the cache.

Because the Queuing service works across networks it's a really neat way to provide scalabity in web applications - if you can't wait for SQL 2005 which will provide cache invalidation on database updates as standard.

Simon.

Re:Done this for years (1)

cablepokerface (718716) | more than 9 years ago | (#12406083)

In ASP.NET you can even do cache invalidation when the database changes

That's right. Have you also tried ASP.NET 2.0 yet? (still in beta though). You don't have to do any extra works whatsoever. You can just say: Hey I want this data in the webapplication to be valid until that stored proc has a different resultset. No programming involved. It's really awesome.

PHP-ADODB Caches these queries (3, Informative)

displague (4438) | more than 9 years ago | (#12405736)

With ADODB for PHP (and perl http://adodb.sf.net/ [sf.net] , you can call CacheGetAll, CacheExecute, etc... The query resultset is saved to a temporary file. This avoids having to create the cache within the same function you would normally call without having to write extra code.

[first useful post?]

Re:PHP-ADODB Caches these queries (1)

displague (4438) | more than 9 years ago | (#12405750)

Correction: should read "and python" not "(and perl."

You answered my question b4 I asked, partially .. (1)

RedLaggedTeut (216304) | more than 9 years ago | (#12405759)

At least partially.

So, you can save result in a file, but can yo usave them in memory too, using PHP?

Re:You answered my question b4 I asked, partially (1)

liquidpele (663430) | more than 9 years ago | (#12405839)

Not totally sure, but last time I checked no.
That's the one major thing I hate about php actually... If anyone knows of a way to store stuff in memory throughout php sessions I would *love* to hear about it though.

You *could* have php call a personal daemon that will store values in memory for you, but that's just not the way it should have to be.

Re:You answered my question b4 I asked, partially (1)

RussGarrett (90459) | more than 9 years ago | (#12405857)

Memcached [danga.com] . I think you'll find that is actually the way it should be.

Re:You answered my question b4 I asked, partially (1)

Rakishi (759894) | more than 9 years ago | (#12405911)

Make a virtual hd? (memdrive or whatever its called).

It seems that php docs state:
" Optionally you can use shared memory allocation (mm), developed by Ralf S. Engelschall, for session storage. You have to download mm and install it. This option is not available for Windows platforms. Note that the session storage module for mm does not guarantee that concurrent accesses to the same session are properly locked. It might be more appropriate to use a shared memory based filesystem (such as tmpfs on Solaris/Linux, or /dev/md on BSD) to store sessions in files, because they are properly locked."

Somewhere else it says:
"To use shared memory allocation (mm) for session storage configure PHP --with-mm[=DIR] ."

You can probably google to get more info, but it seems that mm is a viable alternative.

Caching improves database performance. (-1, Redundant)

minkie (814488) | more than 9 years ago | (#12405742)

Film at 11.

You forgot something... (0)

Anonymous Coward | more than 9 years ago | (#12405743)

Were's the patent?

using smarty template (0)

chrisranjana.com (630682) | more than 9 years ago | (#12405762)

and of course smarty.php.net is there too !

Java Servlet init question .. (1)

RedLaggedTeut (216304) | more than 9 years ago | (#12405776)

In init(), there is
ListValuesLoader listValues = new ListValuesLoader();
but no global.

However, I can't find the object where the data is actually cached. Is it a Singleton somewhere? Pretty well hidden it must be ..

Re:Java Servlet init question .. (2, Informative)

Vengeance (46019) | more than 9 years ago | (#12406038)

The individual list types are all implemented as singletons.

That is, they have static 'getInstance' methods, maintain private static references to their own solitary instance, and have private constructors.

This is a very standard OO pattern, and seems to be one thing the article got essentially right.

SQL (1)

smitty_one_each (243267) | more than 9 years ago | (#12405781)

For additional style points, load all lookup tables in one query, and concatenate the HTML into the values.
But I may be the Kurtz [wikipedia.org] of SQL...

Is This Consultant on YOUR Payroll? (5, Informative)

rimu guy (665008) | more than 9 years ago | (#12405782)

If you have yet to read the 25-page FA, may I present the precis:

Database hits are expensive. Reduce them where possible. For example, cache static lookup data.

The simplicity of the point however is lost in the complexity of the article. It covers web.xml settings, servlet classes, list value loaders, persistence backends for said loaders, data source 'helpers' for said loaders, custom object classes for the loaders, several subclasses for said object classes, and a jsp page (to boot). Phew.

The author refers to this design as a quick and easy approach. It is not. If you are not familiar with Java and read this article, please do not be put off. He could have demonstrated the point with a far simpler example. E.g. static variable, sql statement, jsp code, done.

[The author] has worked with IBM Global Services for one year, and has five years of experience in J2EE-related technologies. And it shows. I dread to think how much a fully realized IBM Global Services project would cost should all its consultants apply this sized sledgehammer to each small task. Hopefully the article was not written up on the client's dime as well.

--
Java Hosting [rimuhosting.com]

Re:Is This Consultant on YOUR Payroll? (1)

Vengeance (46019) | more than 9 years ago | (#12405946)

I have come to expect this kind of thing from IBM consultants. This guy is a 'Lead Developer', and he's writing a Software 101 article, padded with extraneous crap in a likely effort to meet some imposed minimum length.

Umm... (0)

Anonymous Coward | more than 9 years ago | (#12405785)

How is this news? This is a random tutorial article from the net. Not newsworthy at all.

GoF Decorator pattern is better for this task (4, Insightful)

MarkEst1973 (769601) | more than 9 years ago | (#12405788)

Assuming one writes a well-factored application, I believe Decorator makes a much better caching mechanism that what the article presents.

A Data Access Object should have 1) an interface (defining add, remove, retrieve, etc.) and 2) a standard implementation of the interface that reads/writes to the database on every method invocation.

A Decorator can implement the data access interface, delegating all method invocations to a wrapped instance of the standard implementation. Decorate the behavior of the standard impl. by providing a cache, checking the cache before retrieving a model and updating the cache before saving a model.

Because the standard impl. and the decorator share the same interface, you can have a factory create instances for you. Your code doesn't know or care which instance it is using. Mix and match Decorators to your heart's delight. A logging Decorator (track what data is being access, etc.) can be thrown into the mix, and again your calling code wouldn't be the wiser.

This pattern is easily unit tested and load tested. It doesn't require a running web container to test or run. It Just Works(tm).

Well, duh (4, Insightful)

Tim C (15259) | more than 9 years ago | (#12405798)

It's called caching, and it's been done since people had to load in commonly-used external references.

I've not RTFA, so perhaps it's truly excellent, but why the hell has this been posted? Anyone who's writing any sort of application and not making intelligent use of caching is either really junior, or should probably be looking for a new job.

Just use JDO and you're done (0)

Anonymous Coward | more than 9 years ago | (#12405820)

Sheesh. Sometimes I think IBM consultants still live in the 90s.
This is standard procedure and any good JDO implementation will do this for you.

http://en.wikipedia.org/wiki/Java_Data_Objects [wikipedia.org]

Laugh it up fuzzballs (0)

Anonymous Coward | more than 9 years ago | (#12405827)

Laugh while you can, people. Because Srinivasa Rao Karanam is training your replacement as we speak.

How did this make it at Slashdot (-1, Redundant)

CSS (879046) | more than 9 years ago | (#12405829)

very mediocre and how do the slash dot editors let these happen.

Re:How did this make it at Slashdot (1)

tarquin_fim_bim (649994) | more than 9 years ago | (#12406079)

Slashdot editing has been outsourced to India.

cool, ibm advertising (0)

Anonymous Coward | more than 9 years ago | (#12405832)

wow, ibm advert. Nice /. - how much are they paying you to advertise in your stories?

Memcached (2, Informative)

captainclever (568610) | more than 9 years ago | (#12405843)

Or you could use something like Memcached [danga.com] . Works with pretty much any language, and tonnes less hassle. (Thanks LJ ;))

Re:Memcached (1)

captainclever (568610) | more than 9 years ago | (#12405860)

Oh, and you can write postgresql triggers that invalidate or repopulate memcache entries.

News? (3, Funny)

Baavgai (598847) | more than 9 years ago | (#12405855)

Seriously, I've you're into servlets and you haven't been caching non dynamic data, shame on you.

By same token, if you're on of those twits who caches five years of data warehouse information in the application layer, there's a special place in programmer hell for you...

Well duh... (0)

Anonymous Coward | more than 9 years ago | (#12405859)

As the subject :>

Not that bad a hint. (2, Interesting)

Ancient_Hacker (751168) | more than 9 years ago | (#12405864)

Yes, it's obvious to anybody with half a brain. But from the looks of several apps out there, there's a LOT of coding being done by the lower half of the bell curve:
  • One very old 200,000 line app, written in assembler, that could only ever run on one particular CPU, had a #define for the number of bits in a packed character field (6 bits BTW).
  • One really losing Java app does about a bazillion (200+) separate SQL queries to ask for things that have not changed in 50 years. Funny, the app runs slowly, even on a rather hefty server cluster. It runs much slower than the old CICS mainframe app it replaced, which ran in one 30 MHz CPU, 4MB of RAM.
  • Many apps do SQL queries to get the names of the days of the week. And the names of the months. And the abbreviations for same.
  • It's a

Re:Not that bad a hint. (4, Funny)

ergo98 (9391) | more than 9 years ago | (#12405916)

  • It's a


Looks like you had an SQL Statement timeout there.

Re:Not that bad a hint. (0)

Anonymous Coward | more than 9 years ago | (#12406111)

Many apps do SQL queries to get the names of the days of the week. And the names of the months. And the abbreviations for same. Well if you were living in Kazakhstan (or one of the other -stans) where the dictator went around renaming days and months in honour of friends and family members, this might be handy if they change on a regular basis.

And for the follow-up article... (5, Funny)

azuroff (318072) | more than 9 years ago | (#12405869)

...this "Lead Developer" at IBM will discover the wonderful performance benefits of pooling database connections, rather than open a new connection every single fricking time he hits the database. No wonder he saw a massive performance increase when he learned how to cache the lookup values.

And what's up with the "obj_" prefixes in some of the code listings? Newsflash: Java is an object-oriented programming language, and most competent Java programmers can figure out that a variable called resultSet probably isn't a primitive. You don't need to waste another 4 characters pointing out that fact.

"Returns the boolean value" (0)

Anonymous Coward | more than 9 years ago | (#12406486)

I really hope this is a joke...

/**
* Returns the boolean value.
* @return boolean
* @param option java.lang.String
*/
public boolean isValidOption(String option) {
option = (option != null) ? option.trim() : option;
return optionsVector.contains(option);
}


The namings are horrible; If I'm using a variable I don't need to be reminded of its type. I certainly don't need to be reminded that my options vector is an object. I do need to know more about a method than its return type. And just to whine, I don't need to set the value of option to option if it is null and certainly don't need to check if my Vector contains it.

Genius - Quick PATENT IT (0)

Anonymous Coward | more than 9 years ago | (#12405895)

Wows thats such genius, it will revolutionise programming. Quick patent it!

recursion, indirection, and... (1)

10am-bedtime (11106) | more than 9 years ago | (#12405905)

...caching (the subject of the article) are the three fundamental algorithms, so it was told to me by a little bird.

of course, i immediately made a base case, trapped the fowl and filled my belly (to put into practice such sound advice, you see ;-). mmmm, cs stew...

What is this post for? (1)

christoofar (451967) | more than 9 years ago | (#12405930)

Any web developer who'se picked up a book for PHP/ or NET Web Development would know how to do this in Apache or IIS.

SQL is the plague of informatics (0)

Anonymous Coward | more than 9 years ago | (#12405969)

A *terrible* language designed not by a computer mechanic but by ignorant math professors. Horrible. Worst part is that the new generation of programmers thinks they should do everything in SQL.

See LK discussion and linus' reply:
>
> Why not to use sql as backend instead of the tree of directories?

Because it sucks?

I can come up with millions of ways to slow things down on my own. Please
come up with ways to speed things up instead.

Linus

Performance? (1)

PIPBoy3000 (619296) | more than 9 years ago | (#12405988)

What's the point of all these fancy new RAID arrays and such if we developers can't get increasingly sloppy with our coding practices?

Though I kid, I find that populating drop-down boxes for applications are pretty minor in the grand scheme of things. My performance issues tend to stem around doing cross-server database queries involving tables with millions of rows. That's when things get slow.

I'm sure there are some people who have to do this level of optimization - folks like Google and Amazon. The only place I've had to deal with this sort of thing is with things like our Intranet home page. In that case, all the drop-down boxes became JavaScript includes that were dynamically recreated every time the database changed. It went from an ASP-based page to completely static, taking considerable load off the server.

What's your Vector, Victor? (2, Insightful)

Vengeance (46019) | more than 9 years ago | (#12406018)

After bracing myself with some more coffee, I read a bit more of this article.

Bad, bad, bad.

What's with the Vectors, anyway? I haven't used those in years.

Breakthrough (1)

Nyhm (645982) | more than 9 years ago | (#12406029)

Wow! What amazing breakthroughs Web developers come up with! Why, soon there might be a good way to maintain client-side state for Web applications. What I will coin as "client-side applications" could provide endless opportunity for rich, dynamic user interaction. These "client-side applications" could even do their own processing and have storage from the local host. If only there were some type of, what I'll call, "socket" to maintain a persistent data connection for protocols designed to fit the needs of the "client" and "server." Some clever web developer will figure how to accomplish this over HTTP...

... It'll take a lot of work, layer upon layer of protocols (all riding on HTTP), and countless new "web technologies," but some day Web-based applications might just become as usable as my hypothetical vision of "client-side applications."

Just In (0)

Anonymous Coward | more than 9 years ago | (#12406099)

That was not for the run-of-the-mill programmers. That was for quiro in californian school.

Lookup Loader library (0)

Anonymous Coward | more than 9 years ago | (#12406118)

The proposed solution is not rocket science, but as the examples suggest, there can be a fair amount of code to get there, which can sometimes be tedious to implement (especially when having many such lists).

One may want to look at automating this process using a product like the (open source) Lookup Loader library (http://www.esslibraries.com/ess/libraries/lookup/ home.do [esslibraries.com] or http://sourceforge.net/projects/esslibraries [sourceforge.net] ). Its purpose is to automate the (re)loading of such lists as much as possible. Configuration can be done through XML files. The library is extensible and not limited to databases and fully supports I18N data (something the article does not mention).

Is this guy for real? (0, Redundant)

955301 (209856) | more than 9 years ago | (#12406133)

Wow, if you can publish an article about not loading the same data over and over again, then I've got some work to do!

How about an article on how to make an application run the same operation over and over instead of repeatedly executing it from a cron job?

Or an article about keeping your strings in a string table instead of dispersing them throughout your code?

Or perhaps I could write about how to use cut-and-paste to aid in producing Javadoc instead of typing @parameter over and over again?

Is this jackass for real? Publishing this garbage is almost as bad as filing for patents on trivial extensions of ideas. I hope the author at least realizes the only good to come from it is to pad his resume.

Slashdot-Talking about the obvious for years! (0, Redundant)

siberian (14177) | more than 9 years ago | (#12406170)

Lame, this is basic stuff. Give me a break.

Hmmmm (1)

mgbaron (457884) | more than 9 years ago | (#12406174)

The solutions provided in this article have very limited usefulness. I support the inclusion of a good web efficiency article on slashdot, but this article is a waste of time and its techniques are a waste of energy unless, for some reason, your site uses a ton of dropdowns.

I read another article on IBM once about web efficiency that was much more thourough and much more slashdot worthy, but I can't find it unfortunately. When I do, I will post it.

If this is news for slashdot.... (0)

Anonymous Coward | more than 9 years ago | (#12406255)

...no wonder the site is so slow.

- Anonymous

Externalize Picklists... (3, Insightful)

zettabyte (165173) | more than 9 years ago | (#12406444)

He should be externalizing the picklists to a .properties file. He'll get the caching through Properties and the strings will be ready for localization.

If the picklists are at all updateable while the application is running, he can cache as he does, but he'll a mechanism to invalidate the cache and re-read from the database.

Forgetting that for a moment:
  1. Hungarian notation is NOT necessary in Java. Period. End of story.
  2. No one uses Vector anymore.
  3. There are some nice tag libraries, so STOP PUTTING JAVA CODE IN JSPS!
If you're a code monkey, memorize these two quotes:
Increasingly, people seem to misinterpret complexity as sophistication, which is baffling - the incomprehensible should cause suspicion rather than admiration. - Niklaus Wirth
and
...it is simplicity that is difficult to make. - Bertholdt Brecht
(quotes from http://www.vanderburg.org/Misc/Quotes/soft-quotes. html [vanderburg.org] )

Almost ...can be viewed as an exercise in caching (1)

Terje Mathisen (128806) | more than 9 years ago | (#12406467)

"Almost all programming can be viewed as an exercise in caching."

For the last ten years or so, this has been my .sig, and this article is just a pretty bad example:

Yes, you should probably cache some or most of this stuff, but you should also consider which of these lists might contain dynamic data:

Is it enough to reload the list at application startup, every N days/hours/minutes, or would it be possible to send a signal from the updating process to trigger a reload only when needed?

Terje
Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Create a Slashdot Account

Loading...