archive-ca.com » CA » E » EVANJONES.CA

Total: 397

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Kill "Summary Paragraphs" in Academic Papers (evanjones.ca)
    similar information free connecting sentences In the next section we discuss from your papers This will give you more precious space to actually talk about your work I was happy to discover I m not the only one who just skips these paragraphs Margo Seltzer professor of Computer Science at Harvard skips them as well True confessions here I never read the summary paragraph in most papers I recommend reading

    Original URL path: http://www.evanjones.ca/summary-paragraphs.html (2016-04-30)
    Open archived version from archive


  • Builds are Complicated: C/C++ (evanjones.ca)
    only be determined by pre processing the source file Thankfully compilers like GCC can output this dependency information see the MD switch and build systems like Ninja can include it Thus this is actually a solved problem although some tools don t do this by default Static Libraries At first glance sharing code using static libraries is straightforward When the static library is updated anything that depends on it needs to be relinked However if that library e g libParent a depends on other libraries e g libChild a then an executable that links the parent library must explicitly link all transitive dependencies both libParent a and libChild a Some linkers care about the order only searching for symbols in libraries that appear later on the command line Thus the libraries must be ordered so that higher level libraries appear first with their dependencies later Generated Code Tools that generate source code are not uncommon They are widely used for data exchange and RPC systems such as Protocol Buffers or Thrift This means that first a generator tool must be compiled next the tool generates the code and finally the generated code is compiled Generated headers are particularly problematic C C programmers expect to be able to include any header without needing to do any build configuration Thus the build system could try to compile a file before generating the needed headers causing the compiler to complain about missing includes To fix this the build system must support some special ordering rules for generated headers One solution is if a library includes generated code the headers must be generated before anything that depends on it is compiled Ninja supports order only dependencies to handle this Third Party Dependencies The worst complications come from third party libraries To include a dependency

    Original URL path: http://www.evanjones.ca/build-c.html (2016-04-30)
    Open archived version from archive

  • Building Software is Hard (for good reasons) (evanjones.ca)
    process gets longer It starts taking forever to rebuild when a single file changes There are mysterious errors that go away by doing a clean build from scratch It turns out that getting a complex build system to work well is hard I used to think the reason is that the tools were bad I ve since learned more about this and I ve changed my mind Building software is hard because there are many policy decisions that need to be made and there are no correct answers As a result the tools are very configurable and complicated and each project works slightly differently This complexity is the reason I like the Ninja build system It takes the opposite stance it is explicitly not very configurable Evan Martin created it because Scons and GNU Make were both too slow to compile Google Chrome taking 10 seconds before even starting a compile Ninja on the other hand takes less than a second because it is engineered from the ground up for fast incremental builds To achieve this it has a fairly minimal design it only traverses a dependency graph If the input files are older than the output files then it executes the corresponding build rule Unlike other systems it has no built in knowledge about how any language is compiled so every step must be specified explicitly As a result Ninja is intended to be used with another tool that generates the build rules a meta build system After having worked with it I think this is actually a fairly elegant way to divide the problem space Every build tool needs to compare inputs and outputs to determine if they are up to date which is all that Ninja does This means the higher level policy decisions about how code

    Original URL path: http://www.evanjones.ca/builds-are-hard.html (2016-04-30)
    Open archived version from archive



  • A TCP "stuck" connection mystery (evanjones.ca)
    mail protocols SMTP POP IMAP Thus the client can be left waiting forever You can trigger this behaviour by adding a firewall rule on the server to block the client s ACK packets On Linux iptables A INPUT p tcp dport SERVER PORT tcp flags ALL ACK j DROP However how can this happen without a well timed reboot In my test I start around 200 client connections at approximately the same time Sometimes this causes the Linux kernel s queue of pending connections to overflow a SYN flood This triggers syncookies and prints the following kernel log message Sep 17 22 08 09 vise4 kernel 379367 113864 possible SYN flooding on port 3311 Sending cookies Syncookies causes the server to send a SYN ACK but immediately forget about the connection Then on the client side this huge number of SYN ACK packets arrive causing it to reply with a huge batch of ACK packets Some of these packets get lost because some buffer somewhere overflows I believe this problem is aggravated by the fact that my client load generator is running in a virtual machine so there is extra batching and extra buffers where packets can get dropped As a result on the client some connections are established but the server has forgotten about them because of syncookies Now that I know what is happening I am amazed that this bug happened as frequently as it did Here are all the things that are needed for this to occur The protocol requires the client to wait for the server to send the first message The server gets too many connections at once so it enables syncookies for some of them The client responds with a big batch of ACKs at the same time so some of them get lost somewhere Can this occur in the real world Yes but very rarely The most likely cause is a well timed reboot but some weird packet loss firewalls or a well timed SYN flood could also trigger it Since the world is a big place I suspect that this has absolutely happened to others However without a test set up like mine this would only happen once in a blue moon They would have seen a stuck MySQL client connection that they couldn t explain but they would probably just retry the operation and never see it happen again So how do we fix it First for protocols that have the server send the first message clients should have an application level connection timeout rather than relying on TCP to detect failed connections Really this is good advice for any network application since even if your code is perfect there could be buggy network devices somewhere between the client and the server The official MySQL client library does not do this but it probably should Second if you are using TCP it is better to design your protocol so the client sends the first message This would have fixed this problem

    Original URL path: http://www.evanjones.ca/tcp-stuck-connection-mystery.html (2016-04-30)
    Open archived version from archive

  • LMAX Disruptor: Fast Concurrent Ring Buffer (evanjones.ca)
    is that if you want to distribute work across a pool of threads the Disruptor can t help The FAQ suggests distributing work modulo the number of workers but what happens when one work unit is much more expensive than others for some reason It ends up stalling all the future work assigned to that task ArrayBlockingQueue which they clobber in their benchmarks is much more forgiving My point is that even though their ring buffer is very well designed and tuned for high performance it isn t an appropriate choice for all applications However if you have producer consumer queues in your code you probably should look to see if Disruptors will match your needs and anyone interested in high performance code should read their paper and or blog posts There is also one minor technical thing they discuss in the white paper in a slightly misleading way The paper states that mutex arbitration is achieved by a context switch to the operating system kernel This is not strictly incorrect however I think it is important to note that this happens only when the mutex is contended and the details depend on the implementation For uncontended Pthread mutexes on Linux and Java synchronization the acquire and release operations use the x86 compare and swap instruction CAS without involving the operating system This is very inexpensive and efficient However if the mutex is held or there are other threads waiting then it is true that the kernel is involved although some implementations may spin for a short time in an attempt to avoid context switches In other words while it is true that locks are expensive they aren t as expensive as the small microbenchmark they present make it seem They show the following results for incrementing a 64 bit

    Original URL path: http://www.evanjones.ca/lmax-disruptor.html (2016-04-30)
    Open archived version from archive

  • packagepy: Package a Python script into a single file (evanjones.ca)
    them into a single file It turns out that Python supports executing zip archives so I wrote a program that takes a Python executable script and outputs an executable zip that contains all the modules it depends on excluding any system modules The result Copy one file and run it with some package name How does this work If the first argument to the Python interpreter is a zip file it looks inside it for main py If found it executes it with the contents of the zip added to the module search path To make the zip directly executable you just need to cheat by adding the standard Unix script header usr bin python n Most zip decoders are smart enough to only start decoding after they see the zip header My script attempts to automate creating this zip Usage packagepy executable script output package Code packagepy py This has only been lightly tested so it is likely to break If you find problems please email me my address is on my home page and I ll see if I can figure it out There are probably better ways of solving this problem For example distutils has some way

    Original URL path: http://www.evanjones.ca/software/packagepy.html (2016-04-30)
    Open archived version from archive

  • Producer/Consumer Tasks and the Scheduler (evanjones.ca)
    data is read only and in memory The system looks something like this Without the proxy MySQL uses all available CPU on the system showing 1600 CPU consumption in top since this system has 16 virtual cores With the proxy we would expect that maybe the throughput is a bit lower but we would still use all the CPU available on the server divided between the proxy and MySQL Strangely that isn t what happened Instead we ended up using approximately half the CPU on the system with MySQL using 750 and my proxy using 30 Adjusting the number of clients made no difference So where is the bottleneck I ll give you a hint my proxy is single threaded using non blocking IO to pass data between the client and server connections I was certainly puzzled about this for a few days until I gave my proxy its own core putting MySQL on all other cores taskset is a wonderful tool Suddenly I saw the performance I was expecting The proxy was using nearly 100 CPU and MySQL was using close to 1500 CPU There was no idle CPU time left on the system So why did this happen My first thought was that suddenly I was seeing better cache behaviour However it turns out that the real reason is that the Linux process scheduler was making bad decisions With 100 clients I had 100 MySQL threads all ready to run So the Linux scheduler says great let s distribute CPU time evenly between these 100 MySQL threads and the proxy And there is the problem all 100 MySQL threads respond but then suddenly there is no work for them to do and they are idle because the proxy hasn t been running The proxy needs to run in

    Original URL path: http://www.evanjones.ca/producer-consumer-linux.html (2016-04-30)
    Open archived version from archive

  • Making Writes Durable (evanjones.ca)
    that file may not have been written so your data is lost Thus to be extra paranoid after creating a file you should call fsync on the directory as well fdatasync This makes similar guarantees as fsync except that the file s metadata may not be updated unless the metadata is needed to access the data This basically means it won t update the last modified time but will make sure that all the blocks of the file can be found Since most applications don t care about this metadata this should be the same as fsync but with better performance in some cases msync MS SYNC If you are using a memory mapped file you can call msync with the MS SYNC flag This effectively calls fsync on the file you can see the call in the kernel source mm msync c However I wouldn t recommend using memory mapped IO for this What happens if there is a disk error because a disk fails Your process gets some sort of signal probably SIGBUS You might be able to install a signal handler to figure it out correctly but this seems difficult If you are using Java the JVM crashes if there is an IO error on a MmapedByteBuffer open O DSYNC Opening the file with the O DSYNC flag means that effectively every write operation is followed by fdatasync This might save you a system call but in my experience it performs about the same sync file range In theory this should work as well but for the life of me I can t understand the man page enough to understand how this could be better than fdatasync As a side note I ve found that I get better performance on ext3 and ext4 if I pre fill

    Original URL path: http://www.evanjones.ca/durable-writes.html (2016-04-30)
    Open archived version from archive