473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Data Bulk in Database Write

Oralloy
988 Expert 512MB
Folks,

Pardon my question here, but I am trying to get a handle on I/O levels when writing to a SQLite database.

My requirement is to limit the amount of write to a JFFS file-system, so that we do not suffer catestrophic failure before end of system life.

Two models are held available - keep the database in memory and copy to flash periodically, or just keep the database on the flash.

Do any of you have a way that I might instrument, or otherwise measure the amount of disk change when writing to the database? Either by interrogating the device driver, or through device inspection?

Thank You,
Oralloy
Oct 11 '16 #1
5 1146
weaknessforcats
9,208 Expert Mod 8TB
What do you mean by "writes"? I know the C/C++ write function can write a block of memory in one call but that does not tell you the number of writes to a file system. Do you mean the number of disc sector writes?

I would keep this database on a mirrored server so you run no risk of data loss. Then at prescribed intervals you can copy this database to your JFFS system. Like during a scheduled system maintenance down time. You can't really make the copy with the system up since the data is not stable over the period of the copy.

Post your thoughts. I may not understand your situation.
Oct 11 '16 #2
Oralloy
988 Expert 512MB
weaknessforcats,

You are the recognised expert, so I will try to explain in an intelligible way....

I am working on an embedded system running Linux that has both a hard-disk and flash memory. The flash memory is accessed as a hard disk using the JFFS2 file-system. In addition on hard-disk fail, the system will restart and use the flash in place of the hard-drive, but with a reduced level of writes.

The database is used for systems data collection and periodic reporting. At every report interval the database is emptied. Maximum size that I've seen is about 50 kibyte, so it is rather small. The database is a SQLite database.

There is no option of a mirrored server, nor is the idea worth following at this point.

So, there are two solution options:
  1. Frequent backup of the database file to flash (the JFFS2 file-system).
  2. Run the database directly on the flash.

Both require I/O activity. What I do not know is how best to instrument the options, so that I can demonstrate the number of writes to the flash.

Ignoring compression, I can estimate the writes using the periodic-copy solution as <size-of-file> times <backup-frequency>.

Running the database directly on the flash, I do not know how to estimate the number of bytes written based on SQL writes executed. Although a database write will only modify a portion of the file, there is no easy measure.

So, questions:
  1. How can I watch the file-system and determine the cost of database writes?
  2. What are your thoughs on how to proceed?
  3. Do you have suggestions as to alternate solutions?

I hope that helps you understand my problem a bit better.

Thank You,
Oralloy
Oct 12 '16 #3
weaknessforcats
9,208 Expert Mod 8TB
I found this:

Expand|Select|Wrap|Line Numbers
  1. http://unix.stackexchange.com/questions/225095/how-to-get-total-read-and-write-iops-in-linux
Does this make any sense to you?

How would you know if your writes were too expensive?

Keep in mind that cost of writes is relevant only if a)your code is running bug free (otherwise bug fixes take priority), b)your processor speed cannot be increased by adding virtual machines to the processor chip, c) the number of your calls to the file system is already minimized (count your calls to write), d) you are not using someone else's database handler (you are stuck with that handler's operation), e) etc.,etc,...

Why would your database be on flash instead of RAM? You could allocate a large area of RAM and operate it as a private heap. Then at maintenance time you copy the heap to disc.

I have implemented the private heap approach and it has worked great. If all of your code allocates from thus heap, then by deleting the heap all the allocations disappear. This means all the memory leaks disappeared when the heap was deleted.

I'm still not sure why this embedded system cannot report directly to a cloud like an RFID. Most likely there is a reason. Here you would poll the device and receive the data. Like utility billing.
Oct 16 '16 #4
Oralloy
988 Expert 512MB
Lady WeaknessForCats,

Thank you for getting back to me. I appreciate your deep and thoughtful response. If I was rude, please accept my apologies as that was not my intent.

I had looked at some of those types of articles, and couldn't decide if it was going to give me useful information, or if it would provide a false (or useless) statistic for what I am trying to measure. Also, I was trying to avoid reinvention of wheel, by asking if other folks had solid information or knowledge.

TOO EXPENSIVE: estimate a 10,000 write-cycle life-span for each bit of flash; the computed aggregate write rate should not cause failure over an operational lifetime of ten years. If 10,000 is exceeded, what is the estimate for write-count, and what is the expected system life-span? So, I do not have an exact number, but I have a trivially expressed goal (10,000 write-cycles). Basic threshold is likely a factor of ten low (100,000 write-cycles), but I don't know the exact chip being used (yet). As the flash is accessed with a JFFS2 file-system, there may be error control mechanisms that significantly extend the lifespan.

Seeing how people are pulling that from
Expand|Select|Wrap|Line Numbers
  1. /proc
is quite helpful, as I got lost reading through code and reports without labelled information.

Obviously I need to perform some more interesting and detailed measurements, and see if there is useful information which I can capture.

Your observations are germane:
  1. Bug free is never guaranteed, but I do try my best. Instrumentation which reports incorrect values, or analysis of the wrong sort, can cause incredible long-term problems.
  2. Virtual machines cannot be faster than the host, period end.
  3. Yes, I do minimise calls, although there are other processes that I do not have control over while performing experiments, so I will have to control for them.
  4. I am currently stuck with SQLite, unless I determine that there is a disaster waiting to happen (e.g. destruction of flash).

The current model is that a specific group of transactions will cause an implicit database backup. Other transactions, which do not write critical information, do not cause the backup.

As to running the database from the flash, instead of periodic backups, is that it may actually write less data than copying the (aprox.) 50 kiByte file for critical transactions. This is a solution that I am considering, as it removes a great deal of (unnecessary) system complexity.

I have also considered a backup process that monitors a flag bit for backup-required, and watches the file to determine if it is active, or no. There are some ugly complexity issues involved with this sort of solution, and I will discuss them with you if I am unable to figure out the necessary IOCTL and locking.

As to the database use, I'm on an embedded system with millions of customer units, so power-off, unintended reboots, and other fails are a fact of life. I do not leave customers in an unrecoverable state.

If you'd like, we can discuss in detail the data collection and retention, as I am not adverse to good suggestions.

I will look into your suggested statistics collection and get back to you tomorrow, once I have a chance to work with them.

Many Thanks,
Oralloy
Oct 16 '16 #5
donbock
2,426 Expert 2GB
Do you have the option of using shadow ram for the database? This is a 2-ply RAM device consisting of RAM and nonvolatile storage (typically EEPROM). The device automatically copies EEPROM-to-RAM at powerup and RAM-to-EEPROM at power down. We haven't used this kind of memory in many years -- maybe they don't make it any more.
Oct 17 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Colin Colin | last post by:
I have an ASP program that is getting an error. When I get the error I get Page Cannot Be Displayed along with the line that causes the error and what the error is. What I am not getting is any...
1
by: jani | last post by:
Hi, i am using a database which contains kanji characters with shift-jis encoding, and i want to show the characters in a datagrid. Now i am using a sqldataset as data source, and show the data...
0
by: Tommy Christian | last post by:
Hi! Anyone who knows about saving serialized data to database, coz I have a problem with that. If I just serialize my session data and then deserialize it, it works. But when I save it...
1
by: Manny Chohan | last post by:
Hi Guys, I have a quick question. i am storing long string of data in database with links to images etc sort of like emails. What i do in codebehind is i write the text to textarea sort of like ...
5
by: Tony | last post by:
Ok. im new to programming. and sorry for fuzzy discription :) I am using a program called leechget. this is download manager that i use on the net. When i add a dowload , i can see the information...
0
by: Boris9577 | last post by:
Hello everyone, I need help with reading data from database. I am working with Visual C++ and MS SQL 2005. This is the problem: I have tried to read some values from data base (on a way described...
1
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I made web site using asp.net 2.0 Vb.Net. The project depends on database in the local machine. The web site has • Create User Wizard and • Login form When the user is...
1
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I have probelm that I hung with for three weeks, My problem is I want to read Binary data from database. I will told you what I did : first I declear an array byte and I cast the...
3
by: selvialagar | last post by:
Hi Everybody.. I have lot of data stored in the database depending upon the time the experiment conducted. Once th experiment is completed, i have to store that data into the excel. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.