Forum: Ruby Advice: XML vs. mySQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
61e4ef0d5076de1dc0394511813de311?d=identicon&s=25 David Autry (dautry)
on 2009-04-07 05:08
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)

2) 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

3) 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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-04-07 05:17
(Received via mailing list)
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.
61e4ef0d5076de1dc0394511813de311?d=identicon&s=25 David Autry (dautry)
on 2009-04-07 05:45
Isn't there a drawback in terms of updating old data?

Thanks.

-Dave

Eric Hodel 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.
29ebf90af6107d2eb39b587c7972639c?d=identicon&s=25 Mukund (Guest)
on 2009-04-07 15:20
(Received via mailing list)
Use a database and use memcache.  XML files don't scale.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-04-08 00:17
(Received via mailing list)
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.
This topic is locked and can not be replied to.