Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:46:43+00:00 2026-06-16T06:46:43+00:00

I am running a cron job on my amazon EC2 micro instance every 12

  • 0

I am running a cron job on my amazon EC2 micro instance every 12 hours. It downloads 118MB file and parses it using the json library. This of course makes the instance run out of memory. My instance has 416MB of memory free but then I run the script it drops down to 6 MB and then it is killed by OS.

I am wondering what are my options here? Is it possible to parse this efficiently via Ruby or do I have to drop down to low level stuff like C? I can get a more capable amazon instance but I really want to know if it’s possible to do this via Ruby.

UPDATE:
I have looked at yajl. It can give you json objects as it parses, but the problem is, if your JSON file contains only 1 root object, then it will be forced to parse ALL the file. My JSON looks like this:

--Root
   -Obj 1
   -Obj 2
   -Obj 3

So if I do:

parser.parse(file) do |hash|
  #do something here
end

Since I only have 1 root object, it will parse the entire JSON. If Obj 1/2/3 were root, then it would work as it will give me them one by one, but my JSON isn’t like that and it parses and eats up 500mb of memory…

UPDATE # 2:
Here’s a smaller version of the large 118mb file (7mb):

GONE

It’s parseable, I didn’t just take some bytes off from the file, just so you an see it as a whole. The array I am looking for is this

events = json['resultsPage']['results']['event']

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:46:44+00:00Added an answer on June 16, 2026 at 6:46 am

    YAJL implements a streaming parser. You can use it to read your JSON on-the-fly, so you can operate on the contents as they come in, then discard them (and the generated data structures from them) after you’re done with them. If you’re clever about it, this’ll keep you under your memory limits.

    Edit: With your data, you are really interested in pulling out portions of the JSON object at a time, rather than parsing the whole object. This is significantly trickier, and really requires that you implement your own parser. The nuts and bolts of it are that you want to:

    1. Step into the events array
    2. For each event in the array, parse the event
    3. Pass the parsed event into some callback function
    4. Discard the parsed event and source input to free memory for the next event.

    This won’t work with yajl, since you are dealing with one object here, rather than multiple objects. To make it work with yajl, you’re going to need to parse the JSON manually to discover the event object boundaries, then pass each event object chunk to a JSON parser for deserialization. Something like Ragel could simplify this process for you.

    Of course, it would be easier to just upgrade your AWS instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I'm running a resque cron job to run every hour using resque-scheduler on
I'm running a cron job (every 15 minutes) which takes about a minute to
I have a table with 200 rows. I'm running a cron job every 10
I have a cron job running a PHP script every five minutes; the PHP
I want to prevent users from running my cron job manually. Apart from using
I have a cron job running searching Twitter every 5 minutes, each 5 minutes
I am running a cron job for php using task scheduler on windows server
I am running a cron job every 15 mins thats pulls in feeds and
I'm running an Amazon EC2 'Large' instance - Ubuntu Natty x64 with PHP5 and
I am running a cron job every five minutes which calls a php script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.