Creating Ruby time object causing garbage collection problem -
i absolute newbie without computer science background. mechanical engineer trying implement way remotely monitor power output (and other output data) of inverters in solar power systems install. if exceedingly dumb, apologize in advance.
i'm trying write little ruby program live in ror website's database folder. every 15 minutes (for long system online producing energy), want poll data our customers' inverters (via tcpsocket connection gateway connected customer inverter) , update website's database file new data. loop have looks this:
last_min = time.new.min while(1) tsec = time.new.sec tmin = time.new.min if ( ( tsec == 0 ) && ( tmin - last_min == 1 ) ) # test using 1 minute # poll inverters, update database last_min = tmin end end
when ran @ first, threw segmentation fault error. put gc.disable
top , worked fine (until force quit after couple of min), see if garbage collection issue , seems first creation of time object triggers issue (throws segmentation fault error). know can't have garbage collection disabled infinite loop. how "clean after myself" ruby? can free time objects somehow @ end of every run through loop? saw post gc.start
, couldn't quite understand how works.
also there way run program , see how ram it's using goes? appreciate , advice offer me here. (including advice general architecture of solar power output monitoring system described in beginning!)
i have benefited looking @ of posts on here in journey far , thank in advance!
sounds interesting project.
you need 1 time object per interval, since can arithmetic operations times. example:
t0 = time.new while(1) if ( time.new - t0 >= 60 ) # test using 1 minute # poll inverters, update database t0 = time.new end end
then don't need worry gc issues.
ps. +1 using delayed_job or other way of putting in own thread, or cron if can run own process, since loop or using sleep() block else.
Comments
Post a Comment