MCslp

News and commentary from the desk of MC Brown

  • About
  • About MCslp
  • Planet MCslp
  • MCslp Books
    • 0
      10 Feb 2009

      My Sessions at UC2009

      • Edit
      • Delete
      • Tags
      • Autopost
      I'm speaking at the User Conference this year, with a half-day tutorial and three further sessions. The running theme is performance, both in terms of the performance of your queries, and in terms of scaling up. Scale Up, Scale Out, and High Availability: Solutions and Combinations This is the big tutorial. It's difficult to resolve what I'll be talking about into a few sentences, but think about all of the different technologies available here - replication, partitions, sharding, DRBD, memcached - I'll be talking about all of them, and more importantly combinations of the different solutions and where the potential performance gains and pitfalls are. I'll also be using the opportunity to demonstrate some of the more obscure combinations that you can use to provide the environment you need. How I used Query Analysis to Speed Up my Applications For query analysis, I'll start with some of the basic methods available to us for performance monitoring, including EXPLAIN and DTrace, before I look at the query analysis provided by MySQL Enterprise Monitor. As an advisor to the group I've been looking at it for a while and used it on my own sites to identify a range of different query problems. Improving performance by running MySQL multiple times It isn't talked about much, but there are times when running a single instance of MySQL doesn't get you either the performance or environment that you need to support your applications. In this presentation I'm going to look at some of the benefits, from simply running multiple instances, to using solutions like VMware, Xen, LDOMs, BSD Jails, and Solaris Containers. Using MySQL with the Dojo Toolkit The final presentation is something a little more fun. The Dojo Toolkit is a JavaScript kit for developing AJAX applications. There are some really fun things you can do with Dojo, but getting the best combination and cool and efficient with MySQL is an art. We'll look at two quick examples; the first is a browsable interface to large quantities of data. The other is dynamic graphing using MySQL as the backend. If, within the bounds of any of these presentations there is something you would like covered, please let me know.
      • views
      • Tweet
    • 0
      15 Nov 2008

      Feeding Query Analyzer from DTrace

      • Edit
      • Delete
      • Tags
      • Autopost
      One of the new features in the new release of MySQL Enterprise Monitor is Query Analyzer. As the name suggests, the Query Analyzer provides information about the queries that are running on your server, the response times and row and byte statistics. The information provided is great, and it doesn't take very long to see from the query data supplied that there are places where you could improve the the query, or even reduce the number of queries that you submit. The system works by using the functionality of the MySQL Proxy to monitor the queries being executed and then provide that information up to the MySQL Enterprise Service Manager so that the information can be displayed within the Query Analyzer page. To get the queries monitored, you have to send the queries through the agent which both monitors their execution and sends the information on up to the Manager, along with all the other data being monitored. The team, though, have been a bit clever and opened up the system to allow information to be sent to the Manager using a REST interface. This means that any system capable of providing information that you want to monitor can be sent up to the Manager. Of course, you can’t just send anything, the Manager needs to know how to handle it, but it shows the flexibility of the design and the potential for the future. So how does this help us? Well, one of the new features in MySQL 6.0 that I’ve been working on (with Mikael Ronstrom and Alexey Kopytov) is DTrace probes. We’ve added a bunch of static DTrace probes into MySQL 6.0 (the full set will appear in MySQL 6.0.8, I think) designed to let you monitor the execution of queries within the server. The probes will allow you to see both the top-level information, such as overall execution time, but also deeper so that you can get information about individual row operations, whether the query used the query cache, and whether it used a filesort operation. I haven’t finished the DTrace probes documentation yet, but I have been demonstrating the probes at conferences and talks (including my MySQL on OpenSolaris university session this week). Trust me, you’ll be pleased. I’ve got a separate blog post detailing some of the specifics in the works at the moment. For obvious reasons, there’s a synergy here that should be obvious. Why don’t we feed up data extracted using DTrace and provide that up to the Enterprise Manager? To do this, there are two parts to the process, the DTrace probes and the script hat passes that information up in a suitable format to the manager. The D script is quite straightforward, we initialize the structures, populate the core information that we need (query string, bytes, rows and the time), and the use the remainder of the probes to finalize that information. Let's have look at the script and then go through the detail:
      #!/usr/sbin/dtrace -s
      
      #pragma D option quiet
      
      mysql*:::query-start
      {
         self->query = copyinstr(arg0);
         self->db    = copyinstr(arg2);
         self->rows  = 0;
         self->querystart = timestamp;
         self->bytes = 0;
      }
      
      mysql*:::select-done
      {
              self->rows = arg1;
      }
      
      mysql*:::insert-done
      {
              self->rows = arg1;
      }
      
      mysql*:::update-done
      {
              self->rows = arg2;
      }
      
      mysql*:::multi-delete-done
      {
              self->rows = arg1;
      }
      
      mysql*:::delete-done
      {
              self->rows = arg1;
      }
      
      mysql*:::multi-update-done
      {
              self->rows = arg2;
      }
      
      mysql*:::net-write-start
      {
              self->bytes = self->bytes + arg0;
      }
      
      mysql*:::query-done
      /self->query != NULL/
      {
              printf("%s:%s:%d:%d:%d\n",
              self->query,
              self->db,
              ((timestamp - self->querystart)/1000),
              self->rows,self->bytes);
      }
      First, we set a pragma to quieten down the output so that the DTrace script only reports what we explicitly write out:
      #pragma D option quiet
      In DTrace, the individual execution points are called probes, and probes are triggered each time that point in the code is reached. To specify the probes we want to watch for, you use a special format, provider:module:function:name that identifies the probe by the name of the provider (the application), the module, the function, and the probe, each separated by a colon. We can just specify the provider and probe name, like mysql*:::query-start. It should also be noted that probes are often provided in pairs at the start and end of an operation, so you can identify the start and end of a query by looking for the query-start and query-done probes. The DTrace probes in the server are set-up in a sort of nested structure, going deeper into the query process as needed. Although not at the very top of the execution cycle, the start of the main query processing is identified by the query-start probe. Each time a query is submitted to MySQL, this probe will get triggered, so for us, it is the start of the process. The probe has a number of arguments, but for our purposes we only need the first (arg0), which contains the full query string, and the third (arg2) which contains the name of the database that the query was executed against. We also initialize the row and byte counts, and the time when the query was executed using the built-in timestamp value. All of this information is placed into the special self structure, which is a persistent structure used to share information between the individual probes that get fired during execution.
      mysql*:::query-start
      {
         self->query = copyinstr(arg0);
         self->db    = copyinstr(arg2);
         self->rows  = 0;
         self->querystart = timestamp;
         self->bytes = 0;
      }
      To get the counts of the number of rows, we can't get the information from the query-done probe. This is because different operations actually provide different levels of information. For example, the select-done and insert-done just provide a count of the rows. But the update-done probe provides information both about the number of rows that matched the original WHERE clause, and the count of the number rows actually modified. To record the number of the rows modified by the query, we therefore need to pull out each piece of information individually:
      mysql*:::select-done
      {
              self->rows = arg1;
      }
      mysql*:::insert-done
      {
              self->rows = arg1;
      }
      
      mysql*:::update-done
      {
              self->rows = arg2;
      }
      
      mysql*:::multi-delete-done
      {
              self->rows = arg1;
      }
      
      mysql*:::delete-done
      {
              self->rows = arg1;
      }
      
      mysql*:::multi-update-done
      {
              self->rows = arg2;
      }
      For the bytes retrieved by each query, the information is a bit more difficult to identify. I'm going to cheat a bit and use the bytes sent by mysqld during a net write to the client. There is a limitation here I've skipped, which is that we could report data sent to any client, since I haven't bothered to track connection IDs. I could do this, but it would make the script a little more complicated. Since the net-write-start might be called multiple times for a long query, we calculate a cumulative byte count.
      mysql*:::net-write-start
      {
              self->bytes = self->bytes + arg0;
      }
      That's all of the information collection; now we just need to print out the information when the query completes. We do this by writing out a colon separated list of the information that we've collected. One additional point here though is that to calculate the duration of the query, you take the timestamp recorded when query-start was called away from the current timestamp. Timestamp information is recorded in nanoseconds (yes, you read that right, nanoseconds), so we divide it by a thousand to get it in microseconds, which is what the Enterprise Manager will expected.
      mysql*:::query-done
      /self->query != NULL/
      {
              printf("%s:%s:%d:%d:%d\n",
              self->query,
              self->db,
              ((timestamp - self->querystart)/1000),
              self->rows,self->bytes);
      }
      If you run this script on it's own (against a MySQL running on Solaris/OpenSolaris, with probes, of course), then you'll get output like this:
      SELECT DATABASE()::391:1:44
      show databases:test:947:2:84
      show tables:test:2018:3:74
      select * from t limit 5:test:595:5:51
      To provide the information up to the Enterprise Manager we cannot use D scripts. Instead, a wrapper around the D script will read the raw information produced and then pass that up to the Enterprise Manager. Before we look at that process, it is worth looking at the REST API that has been built in to v2 of the Enterprise Monitor. The interface is available through the standard URL for the Enterprise service, typically your hostname and the port 18080 if you've used the default settings. Therefore we can access the interface using the url http://nautilus:18080/v2/rest/, assuming our host is nautilus. From the base URL, you can start to get information, or put information, about the different entries in the repository using the path in the URL to signifiy what it is we are looking for. Information about instances is within the instance, with the provider as mysql, and the MySQL server as server. Or better put, the base URL would be http://nautilus:18080/v2/rest/instance/mysql/server/. The last fragment of information we need is the UUID. All objects within the repository have a unique ID, and these are split at different levels. For example, an agent has a UUID, and so does the server it is monitoring. In our example, we want the UUID of the MySQL server, which is conveniently stored within the server itself in the mysql.inventory table. Finally, we need the username and password of the agent user. Through the REST API we use basic HTTP authentication, to make the process easy. Putting all of this together, we can get the core information about an instance using wget:
      $ wget -qO mysql.server --http-user=agent --http-password=password \
          'http://nautilus:18080/v2/rest/instance/mysql/server/2b86b277-fb2b-492d-b946-3a2acaec0869'
      If we now look at the output file, mysql.server:
      {
          "name": "2b86b277-fb2b-492d-b946-3a2acaec0869",
          "parent": "/instance/os/Host/ssh:{88:e1:fc:6d:99:69:e4:5f:b4:0a:ec:5a:09:c0:6a:24}",
          "values":     {
              "blackout": "false",
              "displayname": null,
              "registration-complete": "true",
              "repl.groupName": null,
              "server.connected": 1,
              "server.last_error": null,
              "server.reachable": 1,
              "transport": "a3113263-4993-4890-8235-cadef9617c4b",
              "visible.displayname": "bear:3306"
          }
      }
      I wont go into detail about what is here, most of it should be self explanatory. However, there are a few things of note. First, the information is in JSON format. This makes it easy to read and more importantly create. Second, note the notation. The item is identified by its name, and also by it's parent. This is an important construct because it helps identify the different elements with each other. In this case, the MySQL server is associated with a physical host (/instance/os/Host) and the individual host is identified by a SSH key, which is one of the alternative UUID formats support by the Enterprise Server to identify individual entities. When submitting information, we need to flip the process around. We don't use a GET request to obtain the information, we use a PUT to send up a JSON packet containing the information we want. The URL for sending the information depends on what we are uploading. The main element for the statements used for Query Analyzer is the statementsummary. The URL for this is http://nautilus:18080/v2/rest/instance/mysql/statementsummary/. For the identifier at the end of the URL, you use a period-separated list that includes the UUID of the MySQL server, the name of the MySQL database the SQL statement relates to, and an MD5 hash of the SQL statement text. For the actual packet, we use the following format, taken here from the Perl script:
      {
          "name": "$server_uuid.$quanbase->{dbname}.$md5",
          "parent": "/instance/mysql/server/$server_uuid",
          "values" : {
              "count": "$quanbase->{count}",
              "text": "$quanbase->{query}",
              "query_type": "$quanbase->{qtype}",
              "text_hash": "$md5",
              "max_exec_time": "$quanbase->{max_exec_time}",
              "min_exec_time": "$quanbase->{min_exec_time}",
              "exec_time": "$quanbase->{exec_time}",
              "rows": "$quanbase->{rows}",
              "max_rows": "$quanbase->{max_rows}",
              "min_rows": "$quanbase->{min_rows}",
              "database": "$quanbase->{dbname}",
              "bytes": "$quanbase->{bytes}",
              "max_bytes": "$quanbase->{max_bytes}",
              "min_bytes": "$quanbase->{min_bytes}",
          }
      }
      Most of this should be self-explanatory. Remember that this is a statement summary, which means that we can send up information about multiple invocations of the same statement in one packet. Thus, within the statementsummary packet we have information about the count of invocations of the statement, execution, row and byte counts and maximum/minimum of each of them, and then the core information like the actual query text, database name, and query type (SELECT, INSERT, etc). Once again, note the name and parent. Here the name is the same tuple as used in the URL, the UUID of the MySQL server, the database, and the hash of the query. This is used as the identifier for this query within the repository and allows us to uniquely identify the query, and the query execution on this server. The parent is the location of, and UUID of, the MySQL server. Now, the Perl script that collates the information from our D script has to do two things, first read the raw output that we create with the D script, and second, supply this up as a PUT request to the Enterprise Server. Dealing with the latter part first, I've used Perl and LWP (libwww-perl) module to construct a suitable request object with the HTTP authorization attached:
      my $header = HTTP::Headers->new;
      $header->content_type('text/text');
      $header->authorization_basic('agent','password');
      my $res = LWP::UserAgent->new();
      Once we've constructed a packet, sending it is a case of specifying the URL, the header, and the content:
      $header->content_length(length $bio);
      my $req = HTTP::Request->new(PUT => $url, $header, $bio);
      
      $res->request($req);
      The bulk of the rest of the script is devoted to reading the information from the D script output, and assembling the packet and min/max values per query. Within the Query Analyzer, the SQL statements are normalized, or canonicalized so that variables are replaced with a question mark. This ensures that we are tracking the query and not the individual values. The significance here is that we want to compare the raw SQL statement, of which there may only be a few hundred in a typical application, not each individual query with it's WHERE and other clauses. Hence, the statement:
      SELECT photoid,title from media_photos where photoid > 23785 limit 15
      Would be normalized to:
      SELECT photoid,title from media_photos where photoid > ? limit ?
      For the Perl script, I do just one type of normalization, removing the value from a LIMIT clause.
      #!/usr/bin/perl                                                                                                                         
      use Data::Dumper;
      use LWP;
      use HTTP::Request;
      use Digest::MD5 qw/md5_hex/;
      
      my $server_uuid = '2b86b277-fb2b-492d-b946-3a2acaec0869';
      
      my $header = HTTP::Headers->new;
      $header->content_type('text/text');
      $header->authorization_basic('agent','password');
      my $res = LWP::UserAgent->new();
      
      my $interval = shift || 20;
      
      print "Sending queries every $interval statement(s)\n";
      
      open(DTRACE,"./merlin.d|") or die "Couldn't open DTRACE\n";
      
      my $counter = 1;
      my $querybase = {};
      
      while()
      {
          chomp;
          my ($origquery,$dbname,$time,$rows,$bytes) = split m{:};
      
          my $query = $origquery;
          $query =~ s/limit \d+/limit ?/g;
      
          $querybase->{$query}->{dbname} = $dbname;
          $querybase->{$query}->{query} = $query;
          $querybase->{$query}->{count}++;
          $querybase->{$query}->{rows} += $rows;
          $querybase->{$query}->{bytes} += $bytes;
          $querybase->{$query}->{exec_time} += $time;
      
          if (exists($querybase->{$query}))
          {
              $querybase->{$query}->{max_rows} = $rows if ($rows > $querybase->{$query}->{max_rows});
              $querybase->{$query}->{min_rows} = $rows if ($rows {$query}->{min_rows});
              $querybase->{$query}->{max_bytes} = $bytes if ($bytes > $querybase->{$query}->{max_bytes});
              $querybase->{$query}->{min_bytes} = $bytes if ($bytes {$query}->{min_bytes});
              $querybase->{$query}->{max_exec_time} = $time if ($time > $querybase->{$query}->{max_exec_time});
              $querybase->{$query}->{min_exec_time} = $time if ($time {$query}->{min_exec_time});
          }
          else
          {
              $querybase->{$query}->{max_rows} = $rows;
              $querybase->{$query}->{min_rows} = $rows;
              $querybase->{$query}->{max_bytes} = $bytes;
              $querybase->{$query}->{min_bytes} = $bytes;
              $querybase->{$query}->{max_exec_time} = $time;
              $querybase->{$query}->{min_exec_time} = $time;
          }        
      
          if (($counter % $interval) == 0)
          {
              print STDERR "Writing quan packets ($counter queries sent)\n";
              foreach my $query (keys %{$querybase})
              {
                  send_quandata($querybase->{$query});
                  delete($querybase->{$query});
              }
          }
          $counter++;
      }
      
      
      sub send_quandata
      {
          my ($quanbase) = @_;
      
          my $urlbase = 'http://nautilus:18080/v2/rest/instance/mysql/statementsummary/%s.%s.%s';
      
          my $md5 = md5_hex($quanbase->{query});
          my $url = sprintf($urlbase,$server_uuid,$quanbase->{dbname},$md5);
      
      my $bio = {dbname}.$md5",
          "parent": "/instance/mysql/server/$server_uuid",
          "values" : {
              "count": "$quanbase->{count}",
              "text": "$quanbase->{query}",
              "query_type": "$quanbase->{qtype}",
              "text_hash": "$md5",
              "max_exec_time": "$quanbase->{max_exec_time}",
              "min_exec_time": "$quanbase->{min_exec_time}",
              "exec_time": "$quanbase->{exec_time}",
              "rows": "$quanbase->{rows}",
              "max_rows": "$quanbase->{max_rows}",
              "min_rows": "$quanbase->{min_rows}",
              "database": "$quanbase->{dbname}",
              "bytes": "$quanbase->{bytes}",
              "max_bytes": "$quanbase->{max_bytes}",
              "min_bytes": "$quanbase->{min_bytes}",
          }
      }
      EOF
      
      $header->content_length(length $bio);
      my $req = HTTP::Request->new(PUT => $url, $header, $bio);
      
      $res->request($req);
      }
      The basic structure is:
      1. Open the DTrace script
      2. Read a line
      3. Add that to the temporary list of queries I know about, adding stats
      4. When I've read N queries, send up the stats about each query as a JSON packet to the Enterprise Manager
      5. Repeat
      Depending on how busy your server is, you may want to adjust the interval when the stats data is uploaded. The default is every 20 queries, but when running on a really busy server, or when running benchmarks, you might want to up that to prevent the script spending too much time sending fairly small packets of stats up. If you run the script, it should just work in the background:
      $ ./dtrace_merlin.pl 
      Sending queries every 20 statement(s)
      Writing quan packets (20 queries sent)
      Writing quan packets (40 queries sent)
      Writing quan packets (60 queries sent)
      That's it! I set this up and then sent some random queries to the server. The following graphic shows the query data only from the DTrace sourced information.
      Media_httpcoalfacemcs_qwzaz
      There are some limitations to the current script. I don't do full normalization, for example, and I dont send the detailed information about individual statements up at the moment. There is also an EXPLAIN packet that you can send that contains the output from an EXPLAIN on a long running query. I could do that by opening a connection to the server and picking out the information. But what I'd really like to do is use the DTrace-based output to show the detail of each part of the query process and the EXPLAIN output. I'm sure I can work on that with the Enterprise team.
      • views
      • Tweet
    • 0
      10 Nov 2008

      Compiling MySQL Workbench on Gentoo

      • Edit
      • Delete
      • Tags
      • Autopost
      The Workbench team have just announced the release of Workbench for Linux, including binary packages and source packages with instructions on how to build. I'm a Gentoo Linux user, so I prefer building from source, and you'll need to emerge the following packages (and note the USE) requirement as part of the source build process:
      # USE="svg" emerge libzip libxml2 libsigc++ \
          libglade libgtksourceviewmm media-libs/glut mysql lua \
          ossp-uuid libpcre libgnome gtk+ pango cairo
      Depending on your config and platform, you may need to bypass some package masking by adding the packages to your /etc/portage/package.keywords file. Then download and install the ctemplate library from google code page. The current Gentoo version is 0.90, and you really should install the 0.91 version. With the required packages and libraries in place, download the Workbench sources and then build:
      # cd mysql-workbench-5.1.4alpha
      # ./autogen.sh
      # make
      # make install
      That should build and install MySQL Workbench for you. Just to confirm, here's a screenshot of the built Workbench running on Gentoo Linux and displaying to my Mac OS X-based desktop.
      Media_httpcoalfacemcs_njfld
      • views
      • Tweet
    • 0
      13 Oct 2008

      How to analyze memory leaks on Windows

      • Edit
      • Delete
      • Tags
      • Autopost
      We use valgrind to find memory leaks in MySQL on Linux. The tool is a convenient, and often enlightening way of finding out where the real and potential problems are location. On Windows, you dont have valgrind, but Microsoft do provide a free native debugging tool, called the user-mode dump heap (UMDH) tool. This performs a similar function to valgrind to determine memory leaks. Vladislav Vaintroub, who works on the Falcon team and is one of our resident Windows experts provides the following how-to for using UMDH:
      1. Download and install debugging tools for Windows from here MS Debugging Tools Install 64 bit version if you're on 64 bit Windows and 32 bit version otherwise.

      2. Change the PATH environment variable to include bin directory of Debugging tools. On my system, I added C:\Program Files\Debugging Tools for Windows 64-bit to the PATH.

      3. Instruct OS to collect allocation stack for mysqld with gflags -i mysqld.exe +ust. On Vista and later, this should be done in "elevated" command prompt, it requires admin privileges.

        Now collect the leak information. The mode of operation is that: take the heap snapshot once, and after some load take it once again. Compare snapshots and output leak info.

      4. Preparation : setup debug symbol path. In the command prompt window, do

        set _NT_SYMBOL_PATH= srv*C:\websymbols*http://msdl.microsoft.com/download/symbols;G:\bzr\mysql-6.0\sql\Debug

        Adjust second path component for your needs, it should include directory where mysqld.exe is.

      5. Start mysqld and run it for some minutes
      6. Take first heap snapshot

        umdh -p:6768 -f:dump1

        Where -p: actually, PID of my mysqld was 6768.
      7. Let mysqld run for another some minutes
      8. Take second heap snapshot

        umdh -p:6768 -f:dump2

      9. Compare snapshots

        umdh -v dump1 dump2 > dump.compare.txt

      10. Examine the result output file. It is human readable, but all numbers are in hex, to scare everyone except geeks.
      11. gflags -i mysqld.exe -ust

        Instruct OS not to collect mysqld user mode stacks for allocations anymore.

      These are 10 steps and it sounds like much work, but in reality it takes 15 minutes first time you do it and 5 minutes next time. Additional information is given in Microsoft KB article about UMDH KB 268343.
      • views
      • Tweet
    • 0
      19 Mar 2008

      New VoiceXML/XQuery Demo

      • Edit
      • Delete
      • Tags
      • Autopost
      I've got a new VoiceXML/XQuery article coming out, and IBM have asked that a demo of the service is live. The service is an interface RSS reader - you get to choose the topic and the feed (currently only four static feeds are provided), then it will read out the feed content. You can try out the demo by calling:
      • Skype: +99000936 9991260725
      • US (freephone): (800) 289-5570, then using PIN 9991260725
      Occasionally the hosting times out, in which case, please contact me and I'll check it out and restart or reboot the service.
      • views
      • Tweet
    • 0
      11 Feb 2008

      An introduction to Eclipse for Visual Studio users

      • Edit
      • Delete
      • Tags
      • Autopost
      I'm seeing more and more people moving to Eclipse as a development platform, even those Windows users who have traditionally used Visual Studio. As an Eclipse user for quite a while now I'm often asked how good it is, or how to use it. Of course, telling people to simply try it out isn't enough. Many people just don't get Eclipse and cannot understand or translate the skills and experience they already have to the Eclipse environment. That's where An introduction to Eclipse for Visual Studio users can help. It's a quick overview of the fundamentals of Eclipse from the perspective of a Visual Studio user. For a more in depth examination, there's a tutorial Eclipse for Visual Studio developers, and another on migrating your applications from VS to Eclipse: Migrate Visual Studio C and C++ projects to Eclipse CDT. I can recommend any (or indeed all) of these.
      • views
      • Tweet
    • 0
      10 Aug 2007

      Brian is having the same issues

      • Edit
      • Delete
      • Tags
      • Autopost
      I mentioned the problem with setting up the stack on a new Solaris box yesterday and then realized this morning that I'd already added Brian Aker's blog posting on the same issues to my queue (Solaris, HOW-TO, It works... Really...). Brian mentions pkg-get, the download solution from Blastwave which I neglected to mention yesterday. It certainly makes the downloading and installation easier, but its's far from comprehensive and some of the stuff is out of date. To be honest I find that I install the stuff from Sun Freeware to get me going, then spend time recompiling everything myself by hand, for the plain and simple reason that I then know it is up to date and/or working or both. This is particularly the case for Perl, which often needs an update of the entire perl binary to get the updated versions of some CPAN modules. Ultimately, though, it sucks.
      • views
      • Tweet
    • 0
      9 Aug 2007

      Setting up the developer stack issues

      • Edit
      • Delete
      • Tags
      • Autopost
      There's a great post on Coding Horror about Configuring the Stack. Basically the gripe is with the complexity of installing the typical developer stack, in this case on Windows, using Visual Studio. My VS setup isn't vastly different to the one Jeff mentions, and I have similar issues with the other stacks I use. I've just set up the Ultra3 mobile workstation again for building MySQL and other stuff on, and it took about 30 packages (from Sun Freeware) just to get the basics like gcc, binutils, gdb, flex, bison and the rest set up. It took the best part of a day to get everything downloaded, installed, and configured. I haven't even started on modules for Perl yet. The Eclipse stack is no better. On Windows you'll need the JDK of your choice, plus Eclipse. Then you'll have to update Eclipse. Then add in the plugins and modules you want. Even though some of that is automated (and, annoyingly some of it is not although it could be), it generally takes me a few hours to get stuff installed. Admittedly on my Linux boxes it's easier - I use Gentoo and copy around a suitable make.conf with everything I need in it, so I need only run emerge, but that can still take a day or so to get everything compiled. Although I'm sure we can all think of easier ways to create the base systems - I use Parallels for example and copy VM folders to create new environments for development - even the updating can take a considerable amount of time. I suggest the new killer app is one that makes the whole process easier.
      • views
      • Tweet
    • 0
      17 Apr 2006

      Building an RPN to Equation Parser

      • Edit
      • Delete
      • Tags
      • Autopost
      In the final part of the examination of lex and yacc, here are the rules for building a parser that translates RPN into equation input (the reverse of the Equation to RPN parser. Translating RPN into standard equation format is a lot more difficult. Although the fundamentals are similar to the RPN parser (we still use a stack for values that are popped off when we see an operand), it is the recording of that process is much more difficult. In the RPN calculator, we can place the result of the calculation back onto the stack so that the value can be used. To resolve something into the equation format we need to record the equivalent expression, not the value. For that, we use a temporary string, and then check if the temporary string has a value and append further expressions to that string. Also, to help precedence in the final calculation (a process handled automatically by the sequence of numbers an operands in RPN) we also enclose each stage of the calculation in parentheses. The resulting rules are shown below. Note that for the example, only the basic operands (+ - * /) are supported, but the principles are valid for any combination.
      %%
      list:   /* nothing */
              | list EOLN
              | list expr EOLN        { printf( "%s\n",exprstring); }
              ;
      expr:   primary
              | expr primary MUL
                {
                  if (strlen(exprstring) > 0)
                    {
                      sprintf(tmpstring,"(%s * %g)",exprstring, pop());
                    }
                  else
                    {
                      sprintf(tmpstring,"( %g * %g )",pop(),pop());
                    }
                  strcpy(exprstring,tmpstring);
                }
              | expr primary DIV
                {
                  temp=pop();
                  if (strlen(exprstring) > 0)
                    {
                      sprintf(tmpstring,"(%s / %g)",exprstring, temp);
                    }
                  else
                    {
                      sprintf(tmpstring,"( %g / %g )",pop(),temp);
                    }
                  strcpy(exprstring,tmpstring);
                }
              | expr primary PLUS
                {
                  if (strlen(exprstring) > 0)
                    {
                      sprintf(tmpstring,"(%s + %g)",exprstring, pop());
                    }
                  else
                    {
                      sprintf(tmpstring,"( %g + %g )",pop(),pop());
                    }
                  strcpy(exprstring,tmpstring);
                }
              | expr primary MINUS
                {
                  temp=pop();
                  if (strlen(exprstring) > 0)
                    {
                      sprintf(tmpstring,"(%s - %g)",exprstring, temp);
                    }
                  else
                    {
                      sprintf(tmpstring,"( %g - %g )",pop(),temp);
                    }
                  strcpy(exprstring,tmpstring);
                }
              ;
      primary: NUMBER { push($1); }
              ;
      %%
      You can see the resulting output below:
      4 5 + 6 *
      (( 4 + 5 ) * 6)
      As mentioned in the original IBM article, we can pipe sequences together to show the parsing and calculation of an expression from different formats. For example:
      $ rpntoequ|calc    
      4 5 + 6 *
      54
      And even rpntoequ and equtorpn:
      $ rpntoequ|equtorpn  
      4 5 + 6 *
      4 5 + 6 *
      The current RPN translator as shown here is not as advanced as the main RPN system, and so it doesn't support all the options, or expression formats, but you can get the general idea. You can download the code for this example: rpntoequ.tar.gz (Unix).
      • views
      • Tweet
    • 0
      17 Apr 2006

      Building an Equation to RPN Parser

      • Edit
      • Delete
      • Tags
      • Autopost
      As part of the continuing examination of lex and yacc, here are the rules for building a parser that translates equations into RPN format. The process is actually very simple. Because of the way the parser works, all you have to do is print out whatever component we see at each stage. For example, when you see a number, print it out, and when you see a operand, also print it out. The basic ruleset is shown below:
      %%
      list:   /* nothing */
              | list EOLN
              | list expr EOLN        { printf( "\n" ); }
              ;
      expr:   shift_expr
              ;
      shift_expr: pow_expr
              | shift_expr LEFTSHIFT pow_expr { printf("> "); }
              ;
      pow_expr: add_expr
              | pow_expr POW add_expr { printf("^ "); }
              ;
      add_expr: mul_expr
              | add_expr PLUS mul_expr  { printf("+ "); }
              | add_expr MINUS mul_expr { printf("- "); }
              ;
      mul_expr: unary_expr
              | mul_expr MUL unary_expr { printf("* "); }
              | mul_expr DIV unary_expr { printf("/ "); }
              | mul_expr MOD unary_expr { printf("% "); }
              ;
      unary_expr: postfix_expr
              | MINUS primary %prec UNARYMINUS { printf("-"); }
              | INC unary_expr { printf("++ "); }
              | DEC unary_expr { printf("-- "); }
              ;
      postfix_expr: primary
              | postfix_expr INC { printf("++ "); }
              | postfix_expr DEC { printf("-- "); }
              | postfix_expr FACT { printf("! "); }
              ;
       primary: NUMBER { printf("%g ",$1); }
              | PI { printf("%g ", M_PI); }
              | OPENBRACKET expr CLOSEBRACKET { }
              | function_call
              ;
      function_call: SIN OPENBRACKET expr CLOSEBRACKET { printf("sin "); }
              | COS OPENBRACKET expr CLOSEBRACKET { printf("cos "); }
              | TAN OPENBRACKET expr CLOSEBRACKET { printf("tan "); }
              | ASIN OPENBRACKET expr CLOSEBRACKET { printf("asin "); }
              | ACOS OPENBRACKET expr CLOSEBRACKET { printf("acos "); }
              | ATAN OPENBRACKET expr CLOSEBRACKET { printf("atan "); }
              ;
      %%
      Why does it work? It has to do with the parser evaluates the different components. When, for example, the parser identifies an addition with this rule:
      add_expr: mul_expr
              | add_expr PLUS mul_expr  { printf("+ "); }
      The code that the parser generates evaluates the sub-rules first, and in both cases the rules will ultimately lead to the numerical value. Each time the number is seen, the value is printed. Once both rules have been resolved, it then matches the full expression and outputs the plus sign. In use, the parser generates all of the necessary RPN:
      4+5*6
      4 5 6 * + 
      (4+5)*6
      4 5 + 6 *
      You can download the source for the equation to RPN parser: equtorpn.tar.gz (Unix)
      • views
      • Tweet
    « Previous 1 2 Next »
    • Search

    • Sites I Like

      • MC's LinkedIn
      • Sharon Penfold's LinkedIn
    • Tags

      • IBM DeveloperWorks
      • Articles
      • Open Source
      • Commentary
      • MySQL
      • Unix
      • Grids
      • Software
      • Hardware
      • General
      • Books
      • Solaris
      • Databases
      • System Administration
      • Interviews
      • ServerWatch
      • Reviews
      • Technology
      • Free Software Magazine
      • Mac OS X
      • Site News
      • LinuxWorld Magazine
      • Web Services
      • Scripting
      • Sun/Solaris
      • Rational
      • Eclipse
      • Linux
      • XML
      • Java
      • Web Development
      • LinuxToday
      • Step-by-step
      • Tips
      • Apple
      • Apple Developer Connection
      • FOSS
      • Computerworld
      • Development Environments
      • Microsoft
      • The Apple Blog
      • Virtualization
      • mysqlconf09
      • Book
      • C/C++
      • CouchOne
      • OS
      • Presentations
      • Windows
      • presentation
      • DTrace
      • OpenSolaris
      • couchdb
      • laptop
      • mysql08
      • mysqluc08
      • notebook
      • Backups
      • DocBook
      • Documentation
      • Example
      • Memcached
      • Web Servers
      • debugging
      • mysql08
      • mysqlconf09
      • mysqluc08
      • query analysis
      • query analysis
    • Archive

      • 2012 (4)
        • March (3)
        • February (1)
      • 2011 (1)
        • September (1)
      • 2008 (1)
        • October (1)
    • Obox Design
  • MCslp

    6439 Views
  • Get Updates

    Subscribe via RSS
    TwitterLinkedIn