Advice: XML vs. mySQL


#1

Hello,

I am new to Ruby and looking for some advice on how to best approach a
problem.

I am writing a Facebook application that will rely heavily on the
manipulation of strings. I want to set up a class, allow users to
create objects based on the class, and write it to XML file or a
database. Each entry will be indexed (integer) for lookup and
identification purposes. When I need to load a specific object I will
build it based on the XML data and the defined class.

  1. Is it possible to define a class and then initialize objects based on
    information contained within an XML file?

Example:

class Car
  attr_accessor :model
  attr_accessor :cost
  attr_accessor :year
end

y = Car.new (XML file contains data for model, cost, and year)
  1. I plan to create XML file names based on the index (id) of the
    object.

    Example: IDs 1000 - 1099 would be in a file named 1000.xml
    IDs 1100 - 1199 would be in a file named 1100.xml

  2. There will possibly be tens of thousands of objects (derived from my
    class) and each object will contain at least 15 variables
    (strings/integers) all written to XML file or mySQL DB. This can
    potentially be a large amount of data. Should I examine mySQL or stick
    with XML? I want to keep this as simple as possible unless resource
    management dictates I take the road less traveled. The speed at which
    the data is accessed is most important. I plan to load into memory the
    files that are currently in use by a user to speed up the process so
    this makes me think that XML would suffice. Hope this makes sense!

Any opinions are welcome.

Thanks.

Dave


#2

On Apr 6, 2009, at 20:07, David Autry wrote:

build it based on the XML data and the defined class.
If these are Ruby objects, why don’t you use Marshal?

I want to keep this as simple as possible unless resource
management dictates I take the road less traveled. The speed at which
the data is accessed is most important. I plan to load into memory
the
files that are currently in use by a user to speed up the process so
this makes me think that XML would suffice. Hope this makes sense!

Marshal is likely going to be significantly faster than any XML
serialization mechanism you write.


#3

Isn’t there a drawback in terms of updating old data?

Thanks.

-Dave

Eric H. wrote:

On Apr 6, 2009, at 20:07, David Autry wrote:

build it based on the XML data and the defined class.
If these are Ruby objects, why don’t you use Marshal?

I want to keep this as simple as possible unless resource
management dictates I take the road less traveled. The speed at which
the data is accessed is most important. I plan to load into memory
the
files that are currently in use by a user to speed up the process so
this makes me think that XML would suffice. Hope this makes sense!

Marshal is likely going to be significantly faster than any XML
serialization mechanism you write.


#4

On Apr 6, 2009, at 20:44, David Autry wrote:

files that are currently in use by a user to speed up the process so
this makes me think that XML would suffice. Hope this makes sense!

Marshal is likely going to be significantly faster than any XML
serialization mechanism you write.

Isn’t there a drawback in terms of updating old data?

Marshal provides methods to help you handle this, if you need them.
Most of the time you won’t so long as you code mildly defensively.
When you do need them, use marshal_dump/marshal_load or _dump/_load.

PS: Don’t top-post, it’s confusing.


#5

Use a database and use memcache. XML files don’t scale.