Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. High load isn't always bad. And it doesn't scale simply onto more processors like that. Moving from 2 cpus to 4 cpus could easily drop a load of 60 down to something more sane like 5, if it's cpu bound. Let's say each cpu can handle 30 processes, and 120 want to run at any one time. With 2 cpus, they will be maxed out with a load of at least 60, because 60 processes are waiting to run. But with 4 cpus, the load will drop much lower, maybe even near zero, with all 4 cpus maxed out (assuming things scale linearly, which is never the case ) I'm also interested to see what happens if webalizer is stopped or paused.
  2. I think left joins are fine as long as you understand how they work. They usually result in SQL fetching rows from the left table, then probing an index for matching rows in the right table. If that index on the right table is missing, you can get awful performance. If you are selecting a subset of data on the left side of the join and then fetching data that may or may not exist on the right hand side with an index, then the left join is usually fine. That looks like what you're doing there.
  3. The iconv() function will do character set conversion. I'm not sure if you apply that to the entire document though.
  4. Here's a non-eval solution: $name = "Request_Version_Blah"; $value = "foo"; function to_array($name_parts, $value) { if (empty($name_parts)) return $value; $first_name_part = array_shift($name_parts); $rest_of_array = to_array($name_parts, $value); $return[$first_name_part] = $rest_of_array; return $return; } $name_parts = explode('_', $name); $result = to_array($name_parts, $value); var_dump($result);
  5. Here's some figures from an I/O bound (but still performing adequately) database server, for comparison. cpu 329108141 1009 30290050 2692689569 956383451 2347601 4304656 cpu0 116845067 763 15330751 64612385 800524411 2347601 4120176 cpu1 9783738 74 2960630 975569679 15455266 0 11718 cpu2 170294175 154 7208641 701713338 124409031 0 155766 cpu3 32185160 16 4790026 950794166 15994742 0 16995 intr 6486707408 1451184649 33 0 0 0 0 0 0 0 0 3 0 902 0 14 0 3051575304 0 0 0 0 0 0 0 0 0 0 0 1983946503 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 19666922524 btime 1189710960 processes 4272352 procs_running 1 procs_blocked 14 14 blocked processes pretty much matches the number of queries running, each one I/O bound. This is a server for importing of data, so being I/O bound is the normal mode of operation. Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie Cpu(s): 6.0% us, 0.5% sy, 0.0% ni, 71.5% id, 21.9% wa, 0.0% hi, 0.1% si Mem: 8226460k total, 8213332k used, 13128k free, 1832k buffers Swap: 979956k total, 3816k used, 976140k free, 7735852k cached This is what you would expect on an I/O bound system with little need for cpu (combined webserver + database is different, because the php code requires more cpu than most SQL queries). The reason the wait percentage is so low is because the other processors are idle. Pressing "1" shows the breakdown: Tasks: 115 total, 1 running, 114 sleeping, 0 stopped, 0 zombie Cpu0 : 27.0% us, 4.0% sy, 0.0% ni, 0.0% id, 69.0% wa, 0.0% hi, 0.0% si Cpu1 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si Cpu2 : 0.3% us, 0.0% sy, 0.0% ni, 38.4% id, 61.3% wa, 0.0% hi, 0.0% si Cpu3 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si Mem: 8226460k total, 8159128k used, 67332k free, 1824k buffers Here you can see that some cpus are totally idle, which is why the average wait percentage shows up as only 20%. The active cpus are doing more waiting than anything else. Load is around 6-8 on this machine. Once load reaches 11 or 12, queries begin to slow down. Load is a very crude measure though, and the threshold for performance problems depends very much on what the machine is doing. Btw, your /proc/stat output shows 2 cpus, which would explain why the percentages add up to more than 100%. To see "top" output for all cpus individually, press "1" while it's running.
  6. There's something really odd with that top output. At the top, it says 0% nice time. But below it says webalizer, which is niced to 19, is using 93% cpu. And the cpu% add up to more than 100% in total. If a niced process is using 93% cpu, then it should say 93% nice at the top. That kind of weirdness can happen with virtual servers, and makes it difficult to see what's really happening
  7. Dual cpu system? The first thing I notice is that webalizer is running on one of the cpus. You may be able to move that to another server. The second thing I notice is that the system is not swapping, but it does have significant I/O and system time. Optimizing Mysql queries may help to reduce those by reducing the need to access disk. As for what to do to reduce the load, the first step is finding out where the time is being spent. The best way to do that is profiling. How to do that depends on the application. If you have a php coder there, you can add some wrappers to time the mysql queries and find any slow ones. You can also add some timing code around major parts of the script, to see which parts take the longest. Once you've found those, you can look closely to see what's going wrong. Often it can be as simple as adding an index to a table that's grown very large.
  8. Yep, that's basically it. I don't know of any simple way to do that encoding. About the &, you may not need that if you are setting the url using window.location. I'm not sure about that. The whole thing about when you need & kinda confuses me actually If it doesn't work, try it as just plain "&"
  9. The "?" in a URL should not be url encoded. The parts to encode are the values of each get variable. In your case, you would encode the value "1" (which just encodes to itself). But if you wanted to set "var=&" for example, you would need to urlencode the "&"
  10. Ok, now that you've verified that var_dump($_POST) works in another script, try it in your contact script. Test it at the very top, and also further down. That should give you enough information. What you should see is that it works at the very top, but suddenly the variables vanish further down. That means they were clobbered inbetween. You might also want to try removing the "@" from the assignments. I don't know why that would make a difference but maybe it will. You can use binary search to find where the variables are being clobbered.
  11. Have you tried posting to a simple script like this: <?php var_dump($_POST); ?> If that doesn't work, then it'll fit into the 128 charater limit If it does work, then you know that the problem is in the script rather than in the webserver.
  12. You must be root to chown a file. You can't give ownership away to someone else. The easiest solution is probably to use permissions to control access. The web server can put the file in a particular group which you have access to as well, and make the file group readable and writeable.
  13. btherl

    looping

    I made it return an array because there are many strings matched. Do you want all the strings to be stuck together into one long string?
  14. I think it's likely that they query is not succeeding. Can you do your queries like this: $result = mysql_query("..."); if ($result === false) die("Error in query: " . mysql_error());
  15. What does it do, and what did you expect it to do?
  16. btherl

    looping

    There's a number of ways to approach this. Using regexp is probably most efficient, but if you're not willing to learn the dark arts yet you can do it with strpos() and substr(). Try this (including the missing end of the function): function split_string($url_fetched,$start_string,$end_string){ $string = $url_fetched; $m1 = $start_string; $m2 = $end_string; $extracted = array(); while ($offset < strlen($string) { $m1_offset = strpos($string, $m1); $m2_offset = strpos($string, $m2); if ($m1_offset !== false) { $extracted[] = substr($string, $m1_offset, ($m2_offset - $m1_offset)); $string = substr($string, $m2_offset + strlen($m2)); # Remove matched portion from input } else { break; # Finish loop, no more mathes } } return $extracted; } I have not tested this code, but the algorithm should work. Basically it chops off the matched portion after finding a match, ensuring that the next match will be found next time around the loop.
  17. Doing this will give you a helpful error message: mysql_query("INSERT INTO cmcats (catid, catup, name) VALUES ('$catid', '$z', '$name')") or die("Mysql error: " . mysql_error()); Note that I have removed the ";" from the end of the first line when I added the "or die"
  18. A simpler way is this: $bytes_written = readfile($filepath); if ($bytes_written === false) die("Error writing file");
  19. That's odd that it doesn't work in IE. Does the same call to ShowProjects() work if you call it elsewhere, such as in the body's onLoad() ? Just to see if the compatibility issue is in how it's called, or in the function itself.
  20. Another option is to use independent javascript that is sychnronized with your cron jobs. For example, if your cron runs every 10 minutes, and your script is executed at 5:03, then you would initialize the javascript with 7 minutes to go. It would then count down to the next cron run without needing to communicate in any way with the cron job.
  21. Ok, then you need to order by MAX(SaidTime), rather than SaidTime. That tells SQL that you want the most recent (the maximum) of all the possible values. If you don't specify MAX() then it may not give an error, but even if it works, you may find that you get values in the wrong order. THat'll be because it picks a random value to order by, rather than always picking the max.
  22. Try an onchange() on the select tag, rather than the option http://www.faqs.org/docs/htmltut/forms/_SELECT_onChange.html You can use javascript to fetch the currently selected value from inside the onchange()
  23. Add this after the call to mysql_query() if ($sel === false) die("mysql_query() failed: " . mysql_error() . "\nQuery: " . $sql . "\n");
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.