Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 24 | */ |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 25 | |
| 26 | #include "table/cs.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/security/key-chain.hpp> |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 28 | |
| 29 | namespace nfd { |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 30 | namespace cs_smoketest { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 31 | |
| 32 | static void |
| 33 | runStressTest() |
| 34 | { |
| 35 | shared_ptr<Data> dataWorkload[70000]; |
| 36 | shared_ptr<Interest> interestWorkload[70000]; |
| 37 | |
| 38 | ndn::SignatureSha256WithRsa fakeSignature; |
| 39 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 40 | reinterpret_cast<const uint8_t*>(0), 0)); |
| 41 | |
| 42 | // 182 MB in memory |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 43 | for (int i = 0; i < 70000; i++) { |
| 44 | Name name("/stress/test"); |
| 45 | name.appendNumber(i % 4); |
| 46 | name.appendNumber(i); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 47 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 48 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 49 | interestWorkload[i] = interest; |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 50 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 51 | shared_ptr<Data> data = make_shared<Data>(name); |
| 52 | data->setSignature(fakeSignature); |
| 53 | dataWorkload[i] = data; |
| 54 | } |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 55 | |
| 56 | time::duration<double, boost::nano> previousResult(0); |
| 57 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 58 | for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2) { |
| 59 | Cs cs; |
| 60 | srand(time::toUnixTimestamp(time::system_clock::now()).count()); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 61 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 62 | time::steady_clock::TimePoint startTime = time::steady_clock::now(); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 63 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 64 | size_t workloadCounter = 0; |
| 65 | for (size_t i = 0; i < nInsertions; i++) { |
| 66 | if (workloadCounter > 69999) |
| 67 | workloadCounter = 0; |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 68 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 69 | cs.find(*interestWorkload[workloadCounter]); |
| 70 | Data& data = *dataWorkload[workloadCounter]; |
| 71 | data.setName(data.getName()); // reset data.m_fullName |
| 72 | data.wireEncode(); |
| 73 | cs.insert(data); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 74 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 75 | workloadCounter++; |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 76 | } |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 77 | |
| 78 | time::steady_clock::TimePoint endTime = time::steady_clock::now(); |
| 79 | |
| 80 | time::duration<double, boost::nano> runDuration = endTime - startTime; |
| 81 | time::duration<double, boost::nano> perOperationTime = runDuration / nInsertions; |
| 82 | |
| 83 | std::cout << "nItem = " << nInsertions << std::endl; |
| 84 | std::cout << "Total running time = " |
| 85 | << time::duration_cast<time::duration<double> >(runDuration) |
| 86 | << std::endl; |
| 87 | std::cout << "Average per-operation time = " |
| 88 | << time::duration_cast<time::duration<double, boost::micro> >(perOperationTime) |
| 89 | << std::endl; |
| 90 | |
| 91 | if (previousResult > time::nanoseconds(1)) |
| 92 | std::cout << "Change compared to the previous: " |
| 93 | << (100.0 * perOperationTime / previousResult) << "%" << std::endl; |
| 94 | |
| 95 | std::cout << "\n=================================\n" << std::endl; |
| 96 | |
| 97 | previousResult = perOperationTime; |
| 98 | } |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 101 | } // namespace cs_smoketest |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 102 | } // namespace nfd |
| 103 | |
| 104 | int |
| 105 | main(int argc, char** argv) |
| 106 | { |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame] | 107 | nfd::cs_smoketest::runStressTest(); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 108 | |
| 109 | return 0; |
| 110 | } |