PUT-KEY-VALUE is sloooooooow

Posted by Patrick Tingen on 23-Aug-2018 06:11

In my DataDigger I save a lot of info into an INI file. In some cases, depending on what the user does, this might add up to hundreds or even thousands of writes in a very short time. Although, 'very short time' is what I wished it would do. 

I already catch all INI write actions, save them into a TT and write them only to disk once every so many seconds, but my observation is that I can write about 60 settings per second using PUT-KEY-VALUE. If you have to write hundreds or even more, this will severely affect the user experience, so are there any options to speed it up?

All Replies

Posted by James Palmer on 23-Aug-2018 06:22

Not using an ini file would be one. In general, wherever possible, I have migrated applications away from using ini files as much as possible. In most applications you can integrate the config into the database, but DataDigger doesn't have its own DB. Have you considered just EXPORTing the temp table to a .d file? As long as you only add fields to the end of the definition it should always work on the import.

Posted by James Palmer on 23-Aug-2018 06:24

Thinking some more, maintaining a custom file in a longchar that you periodically copy-lob to disk might be quicker as well.

Posted by ralphvercauteren on 23-Aug-2018 06:27

Hi Patrick,

Writing some many changes to an INI file or any other file is bad. 60 times a second is not even that bad. With that many read and writes you could use an ssd.

There are a couple of solutions, but a database is the best option.

With regards,

Ralph

Posted by marian.edu on 23-Aug-2018 06:30

Why not just using write-json on that temp-table?


Marian Edu

Acorn IT 
+40 740 036 212

Posted by Patrick Tingen on 23-Aug-2018 06:32

The bad news is that I am already using an ssd. A db would be best, but as James stated, the DataDigger does not have its own database so that is no option. Writing it to disk myself might be the better option here.

Problem is that most of the time there are just a few settings that get flushed to disk. Writing the complete INI might take longer than just using PUT-KEY-VALUE on a handful of settings.

Ah, well, let's test and find out.

Posted by ralphvercauteren on 23-Aug-2018 06:45

Try it with a memory disk, maybe it's going faster.

Posted by ralphvercauteren on 23-Aug-2018 06:45

Try it with a memory disk, maybe it's going faster.

Posted by Matt Gilarde on 23-Aug-2018 07:02

Some anti-virus programs can cause writes to ini files to be slow. Try changing the extension on your ini file to something other than "ini" to see if performance improves. Otherwise, there's not much that can be done to improve the speed of PUT-KEY-VALUE in OpenEdge since the real work is done by Windows function WritePrivateProfileString.

Posted by Richard.Kelters on 23-Aug-2018 07:24

You are using -basekey INI I presume?

Posted by Rob Fitzpatrick on 23-Aug-2018 07:39

I tried a little test to see what's going on in PUT-KEY-VALUE:

define variable i     as integer   no-undo.
define variable v-key as character no-undo.
define variable v-val as character no-undo.

etime( yes).

do i = 1 to 1000:
  assign
    v-key = "foo" + string( i, "9999" )
    v-val = "bar" + string( i, "9999" ).

  put-key-value section "mysection" key v-key value v-val.
end.

display etime.

It took 4.71 sections to create 1000 key-value pairs.  Each call to PUT-KEY-VALUE results in eight file operations:

CreateFile
LockFile
QueryStandardInformationFile
ReadFile
WriteFile
SetEndOfFileInformationFile
UnlockFileSingle
CloseFile

Most of these operations are quick, ranging from about 30 microseconds to maybe a millisecond.  But CloseFile is by far the most expensive, at 4.41 seconds, or 93.5% of the total elapsed time.

So if you want to write a lot of keys all at once with high throughput, maybe James' idea of writing to the file with COPY-LOB would be better as you would only open and close the file once.

Posted by Brian K. Maher on 23-Aug-2018 07:44

What happens if you disable the Offline Files service?
 
 
Brian Maher
Principal Engineer, Technical Support
Progress
Progress
14 Oak Park | Bedford, MA 01730 | USA
phone
+1 781 280 3075
 
 
Twitter
Facebook
LinkedIn
Google+
 
 

Posted by Rob Fitzpatrick on 23-Aug-2018 07:44

Just curious: have you tried using the registry rather than an ini file?  I wonder how the performance would compare.

Posted by Patrick Tingen on 23-Aug-2018 08:12

Yes, I am using -basekey INI for the DataDigger since I would like it to be portable.

I rewrote the procedure that writes the settings so it just writes it to disk itself instead of relying on PUT-KEY-VALUE. The time to write all settings to disk is now consistent; in my testcase 30-35 msec, no matter how many settings changed.

In the old situation, writing took about 12 msec per setting, so from 3 settings or more, this way is faster.

Excellent solution now, thanks everyone.

Posted by Jeff Ledbetter on 23-Aug-2018 08:58

Rob:

"Each call to PUT-KEY-VALUE results in eight file operations:"

Which tool do you use to monitor those operations?

Posted by Brian K. Maher on 23-Aug-2018 09:04

www.sysinternals.com (redirects to MS), download the zip file containing the entire suite to some dir and add it to your OS path.  Very useful stuff.
 
oh, and the tool you want is ProcMon (Process Monitor).
 
 
Brian Maher
Principal Engineer, Technical Support
Progress
Progress
14 Oak Park | Bedford, MA 01730 | USA
phone
+1 781 280 3075
 
 
Twitter
Facebook
LinkedIn
Google+
 
 

Posted by Rob Fitzpatrick on 23-Aug-2018 09:49

Hi Jeff,

As Brian said, I used procmon.

Posted by Peter Judge on 27-Aug-2018 10:26

The other reason to move away from the current approach - for me anyway- is that INI files and PUT-KEY-VALUE are Windows-only capabilities. If you ever want to port to a another OS or UI (even headless) you’ll have to refactor for that anyway.
 
 

Posted by ChUIMonster on 27-Aug-2018 10:52

I never really understoof why that INI file stuff needed to be Windows-only.

I actually thought about using INI files for a while until I discovered that unfortunate restriction.

This thread is closed