D4R issues
Malcolm Hussain-Gambles (1596) 811 posts |
Just wondering if anyone knows if you can actually read data off the socket when an internet_event is called? |
Malcolm Hussain-Gambles (1596) 811 posts |
After debugging and cleaning up my code and more investigation, I now realise why code that uses socketwatch is so dismal. |
Malcolm Hussain-Gambles (1596) 811 posts |
After some more debugging I’ve also found that you can either use FIONBIO (non blocking I/O) on the socket and use select, or use FIONREAD to detect if there is data on the socket and use blocking mode if you really want to. I removed printf’s from my (benchmarking) program for null reads (produces quite a bit) and the Pi 1 then reached 7030 kbytes/sec The tests were doing a http get off my PC at home downloading some random DVD iso image At least this means I’ve got something to aim for! Get the same results (or better if that’s possible) multitasking in a module. |
Malcolm Hussain-Gambles (1596) 811 posts |
Just a quick update to let you know work is progressing. |
Malcolm Hussain-Gambles (1596) 811 posts |
I’ve managed to make some progress again. |
Rick Murray (539) 13840 posts |
What in specific? |
Malcolm Hussain-Gambles (1596) 811 posts |
I can use toolbox to load in the templates as long as they only use a tiny amount of memory. I’m starting to get to grips with toolbox and oslib stuff now and slowly understanding how it actually works – rather than cut & paste guessing. Oh, and I’m really enjoying Ergo Proxy ;-) |
Chris Johnson (125) 825 posts |
Surely the toolbox modules use their own private storage to keep details of the objects you create. You just need to keep copies of the window or menu handles, etc., which are returned when the object is created or autocreated. |
Malcolm Hussain-Gambles (1596) 811 posts |
@Chris – That was my assumption, but when it tries to create toolbox menus it barfs. I’m not sure of the actual fix I’ll need to do – but it’s to do with toolbox and memory allocation, or at least that’s my current theory. I suppose at the moment I don’t care enough to track it down, as I’m actually making good progress without a module. I’ve managed to get to 3.6 to 4.2MB/sec, so I’m hoping my last set of tweaks will bring this up to or close to a stable 5MB/sec – which is still poor, but that’s all it seems the poor panda can do. |
Malcolm Hussain-Gambles (1596) 811 posts |
Thanks to a heads up from Rick, I’ve added some code to set the socket receive buffer size. |
Malcolm Hussain-Gambles (1596) 811 posts |
I thought I’d put up a seriously alpha version, in-case anyone is interested I think a complete rewrite (again) is in order, I really don’t fancy debugging a memory leak – and at least I know how my code needs to be structured now. |
Rick Murray (539) 13840 posts |
Why would you want to? https://www.riscosopen.org/wiki/documentation/show/OS_ConvertFileSize ;-)
No, it is right. 1204 isn’t the same as 1024. :-P Seriously, why are you using divisions to change the magnitude of a file size? You could use “
Are you using The difference is the second method always creates larger numbers so can work with straight integers. The first method may require floats if it isn’t to lose data.
Can RISC OS itself cope with more? For what it is worth, I did a test using the Norcroft/DDE compiler to see what it could optimise.
You would expect the compiler to spot the /1024/1024 and bitshift it, right?
(I think “_kernel_alloc” ought to be “_printf”; the older disassembler isn’t aware of the newer jumptable layout) Very droll. Yes. Very. For the lulz, I gave the same program to TurboC++ v1.01. Even switching to unsigned long, it just wasn’t going to insert the value into the “meh” variable until I casted every single part of the calculation. Pedantic piece of…. Anyway, enjoy this god-awful mess. It has been clever enough to spot that a division by 1024 can be replaced with a shift, but astonishingly it has to call a function to do this as the value is composed of two 16 bit halves so
27 instructions with 7 branches versus 14 instructions with 4 branches. |
Malcolm Hussain-Gambles (1596) 811 posts |
Well, you’ll like my current attempt. I was wondering if it was an issue with doing maths on unsigned ints. I think RISC OS has a 4GB file limit. I did think about handling any filesize by chopping the string up into 32 bit numbers. If I can think of a reason to do it I may do – possibly for streaming where you aren’t saving the file. At the moment there is zero optimisation, as my focus is on memory/buffer logic. Very interesting about the percentages, I never thought about it! As you guessed I use floats to calculate it – which isn’t good. OS_ConvertFileSize looks lovely, the more I can whine about other peoples bad code the better ;-) |
Rick Murray (539) 13840 posts |
Haha. Yeah. That’s one way I guess… …oh bloody hell, you’re being serious, aren’t you?
Look at how you are passing the variable. It sounds like you want to pass by value (your function will be using a copy of the file size value) but you are instead passing by reference (your function will be using a pointer to the file size value, in other words, the real thing). I don’t experience this in my programs because I (almost) never modify any of the variables passed to a function. For example:
versus:
I may be speaking out of my backside (I can’t test as I’m sitting in the sun in the garden ;-) ) but you might have a function accepting the file size variable by reference and then modifying it. For instance:
and:
The difference? A single solitary ‘*’ which instructs C to pass a pointer instead of a copy variable.
The problem here is that when you are streaming, the end position is potentially infinite. When are you going to stop listening to the service? Assuming you can know the future and know the instant you will turn the stream off (and ignoring the fact that the mere fact of knowing and telling your program will affect the time indicated), assuming you know this (and also believe in predestiny), then a percentage makes sense. Otherwise… a percentage of what?
Well, maybe it ought to handle GiB sizes these days? How would a DVD ISO image show up? Something like 4000 MBytes ? A quick deviation while it is in my mind (nothing to do with RISC OS) – I used to use DVD-Rs to back up my data and while this was not a hardship when 8GiB to 20GiB harddiscs were the norm, it is rather less so now that storage is typically fractions of or multiples of terabytes and mere SD cards can be many times bigger than the capacity of a DVD. |
Malcolm Hussain-Gambles (1596) 811 posts |
The sprintf was just to prove 100% that it wasn’t the maths causing the issue – which it isn’t by the looks of it – so whilst I was being serious about doing it, it’s going to be removed as that would be a new level of insanity, even for me! As regards backups, it depends on how much you need the data. A disc copy is not a backup, it’s just a copy – which is handy, but it’s not a backup that should be relied upon. If you want to backup a lot more, then realistically your into enterprise kit… LTO-4 would probably do, we see around 110MB/sec writing to tape which is nice. For home office use, I’d probably recommend a NAS with mirrored disc (QNap or synology) and backup every month or so with a blu ray disc. There’s also “cloud” storage, you can get free amounts of various providers. So: 1) How much are you willing to spend For example if you have a 2 TB NAS with 1.5TB of videos, 0.4 TB of pictures and only 0.1 TB of data. Data management is the key ;-) I could go on, I must stop! |
Malcolm Hussain-Gambles (1596) 811 posts |
This is interesting…. 2% 42948634*100/1969803264 It looks like I can’t multiply by 100 first as it rolls over the unsigned int size, so floats it is. Anyway I got to the bottom of my issues |
Vince M Hudd (116) 534 posts |
If you really want to multiply by 100 first, then perform the division, consider shrinking the numbers in the first place. Using your examples, with the percentages shown as integer results (I’m assuming you aren’t after higher precision): ( 42948634 / 1969803264 ) * 100 = 2% and Consider using >> 10 on both the amount and total before calculating the percentage – i.e. calculate the percentage on kilobytes, rather than bytes: ( 41942 / 1923636 ) * 100 = 2% and Now, Rick’s suggested method should be workable: 41942 * 100 / 1923636 and 41944 * 100 / 1923636 should both return 2%. The reason this works is simply that before dividing by 1024, the original value was approximately 10x bigger than the shifted version will be once it’s been multiplied by 100. If the variable type you’re using can cope with the original value, it can cope with that. If necessary, you could check the total size before deciding whether you need to apply the >> 10 to the values – so for a total size that’s small enough, it doesn’t happen. |
Malcolm Hussain-Gambles (1596) 811 posts |
The main problem is that I don’t really know what accuracy I need until I get the file size. |
Rick Murray (539) 13840 posts |
Remember, a percentage is a “per cent” – a part of a hundred. So any “total size” number over 100 is more than enough to obtain a valid percentage.
I should point out that Vince’s method would not work with integer arithmetic, as the result of So…
Same end result, but can work with straight integers. ;-) In reality, I would recommend the shift being optional; if the file is over a megabyte then shift On the plus side, a user is less likely to notice a percentage going up erratically on a file that takes two seconds to download as opposed to one that takes two hours. ;-)
Hey – you would have to try to be as bad as the Windows “Time remaining” estimations. |
Rick Murray (539) 13840 posts |
Ah-ha. You’re using pointers, so if you alter the contents of the struct, it will have global effect.
That is one of those great unanswerable questions. I would not like to lose the data, but if civil war breaks out or I suffer a major heart attack – then what’s on a harddisc will cease to be of great importance…
Mmm, what do they hold, around 25GiB apiece? I’ll need to look up the prices of the writer and discs.
Ah, so Bluray is 25GiB.
I would prefer a static optical media for the basic ability to stuff them into an envelope and stick them out in the barn – for the basic reason that it doesn’t make any sense to hold backups in the same place as the live copy. If a piece of the ISS should crash into my bedroom, that’ll be everything wiped out…
Ah, but a disc copy on two separate discs is more a backup than a single copy. ;-)
That looks nice. The price is more than a month’s pay, so… yeah… scribble that on the “when I win the lottery” PostIt.
That’ll be a flat NO. The other reason is purely technical – with 2mbit down and 0.5mbit up, cloud services are kinda pointless…
Hehe… ;-) My personal data (source codes and such) can be backed up on an SD card. My photos might take two if I take out the rubbish and the near-dupes (you know, in order to get the right photo you just keep tapping the icon until there are a dozen potentials to choose from). The harddisc content? Mostly animé and dorama and dead wet girls. There are DVDs of some things available, but being English/Chinese subtitled and fitting a 12 episode (~54 minute apiece) series on to 2 or 3 DVDs, I’m not sure it is entirely legitimate – been there, done that.
I don’t have time for that! Just get another harddisc and draggy-droppy. ;-) 1 I do make use of Google Docs (via Google Drive) but since the majority of that is rough copies for my blog (posted publicly) and user guide info (also eventually public), it is less of a concern than, say, scans of my X-ray and medical notes (for instance). |
Steffen Huber (91) 1953 posts |
Blu-Ray is Blu-Ray, but there are the R (write once) and RE (write and erase) variants. As well as the LTH and HTL variants. And the latest member of the family, the M-Disc, which claims an archival life of more than 1000 years. And there are various capacities around – 25 GB, 50 GB, 100 GB. However, I would not recommend the 50 GB and 100 GB variants for long-term backup because of their multi-layer nature and the excessive prices. 100 GB media is not universally compatible, for the M-Disc you need special writers, but it is said to be compatible with all readers. |
Malcolm Hussain-Gambles (1596) 811 posts |
If it’s Japanese Horror, then I’d recommend definitely backing it up ;-) This is a good example of what can happen I use BD-R (write once) – they are fairly cheap for a 25 pack. I knew – and agree with your viewpoint on cloud storage, I mentioned it in case anyone else read it. I’ve added a little screenie from tonight’s work I’ll need to revisit my structs once I’ve finished and clean up and optimise it all. |
Vince M Hudd (116) 534 posts |
Quite so – I wasn’t necessarily suggesting he use that method of calculating the percentages. That’s just the method of calculation I normally use in real life (quite often in my line of work). I therefore instinctively used it to express the calculations and illustrate their results before and after the >>10 Also: Malcolm, as Rick points out, a percentage point is a percentage point is a percentage point. There are 100 integer percentage points between 0 and any size of file. If you are just using it to display a progress bar, for example, then an integer result should be fine. (And given what D4R is, that’s what I’d guess you are doing – hence my assumption you weren’t interested in higher precision). Plus, if you are working with integer values, as per Rick’s suggestion (and the reason for multiplying by 100 first, as well as the reason for bit shifting to avoid problems with numbers being too large) then you’re likely to be looking at integer results anyway. |
Malcolm Hussain-Gambles (1596) 811 posts |
I’ve altered the code to use if >10MB then do a 20 shift if >1M do a 10 shift otherwise don’t shift, that way there’s no loss in accuracy. I don’t how much of an optimisation that is, but it’s looks cleaner to me (no casting) and avoids the horrible use of floats – I suppose it further depends on whether the machine has and uses an FPU or emulates it. As for Ricks mentioning of windows time estimation (it’s much better under 2010) that’s fairly easy. Use a random number to decide how many weeks to increase or decrease the time by and do that again based on a random number. |
Steve Pampling (1551) 8170 posts |
The problem with MS time estimation is a result of the implementation of the display and active transfer process monitored. A logical method would be to implement a file transfer process that called / updated a GUI object to display the progress (possibly with a swirly bit of paper or such like) However what the numpties did was implement a swirly bit of paper display that calls a transfer process at intervals resulting in a transfer that is totally dependent on GUI update speed. Which reminds me: Do we really need every file transferred to be written into a displayed box that (hopefully) only displays the text for a time too short to read it properly or at all? |