It takes about 0.25 seconds to read or write a coinc.xml file. As these files are read or written several times throughout the alert process, this adds up to be a significant source of latency. Perform benchmarking of python-ligo-lw and look for possible performance improvements.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related or that one is blocking others.
Learn more.
It's spending most of its time in C code. Profiling the C code with perf reveals that most of the time is spent in wcstod, a C standard library function to convert a wide char array to a double.
I reasoned that strtod is probably a lot faster than wcstod, and so optimizing python-ligo-lw for ASCII characters might help. To test that idea, I wrote this little benchmark C program: test.c
Indeed, on my Mac, I get the following output:
Called strtod 100000 times 0.000233 seconds - sum was 352431Called wcstod 100000 times 0.733835 seconds - sum was 352431strtod is 3149.51 times faster than wcstod
However, on one of our computing clusters's x86_64 hosts, I get the following:
Called strtod 100000 times 0.00100611 seconds - sum was 1.67891e+06Called wcstod 100000 times 0.00101183 seconds - sum was 1.67891e+06strtod is 1.00569 times faster than wcstod
So the idea of re-writing the C bits of python-ligo-lw to use UTF-8, and replacing wcstod with strtod, is ruled out.
I dug up LIGO-T990023 which documents the LIGO-LW format. The format supports encoding float and double arrays as little-endian or big-endian byte strings, encoded to UTF-8. It is not implemented in python-ligo-lw. Initial benchmarks of this approach, though, look very promising.
I benchmarked it on the sample that I described at the top of this issue on the host ldas-pcdev2.ligo.caltech.edu. Here are the results:
-
Old format
New format
Time to read 111 files
14.3 s
8.64 s
Time to write 111 files
2.13 s
0.423 s
During the process of creating an alert, these files are written once (by the pipeline) and read twice (once by GraceDB, once by BAYESTAR). So the expected speedup per event is (2 * (14.3 - 2.13) + 8.64 - 0.423) / 111 = 0.29 s.
The coinc.xml file sizes also decrease by an average of 38%.