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" |
| 27 | #include "table/cs-entry.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 28 | #include <ndn-cxx/security/key-chain.hpp> |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 31 | namespace cs_smoketest { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 32 | |
| 33 | static void |
| 34 | runStressTest() |
| 35 | { |
| 36 | shared_ptr<Data> dataWorkload[70000]; |
| 37 | shared_ptr<Interest> interestWorkload[70000]; |
| 38 | |
| 39 | ndn::SignatureSha256WithRsa fakeSignature; |
| 40 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 41 | reinterpret_cast<const uint8_t*>(0), 0)); |
| 42 | |
| 43 | // 182 MB in memory |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 44 | for (int i = 0; i < 70000; i++) { |
| 45 | Name name("/stress/test"); |
| 46 | name.appendNumber(i % 4); |
| 47 | name.appendNumber(i); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 48 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 49 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 50 | interestWorkload[i] = interest; |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 51 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 52 | shared_ptr<Data> data = make_shared<Data>(name); |
| 53 | data->setSignature(fakeSignature); |
| 54 | dataWorkload[i] = data; |
| 55 | } |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 56 | |
| 57 | time::duration<double, boost::nano> previousResult(0); |
| 58 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 59 | for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2) { |
| 60 | Cs cs; |
| 61 | srand(time::toUnixTimestamp(time::system_clock::now()).count()); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 62 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 63 | time::steady_clock::TimePoint startTime = time::steady_clock::now(); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 64 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 65 | size_t workloadCounter = 0; |
| 66 | for (size_t i = 0; i < nInsertions; i++) { |
| 67 | if (workloadCounter > 69999) |
| 68 | workloadCounter = 0; |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 69 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 70 | cs.find(*interestWorkload[workloadCounter]); |
| 71 | Data& data = *dataWorkload[workloadCounter]; |
| 72 | data.setName(data.getName()); // reset data.m_fullName |
| 73 | data.wireEncode(); |
| 74 | cs.insert(data); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 75 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 76 | workloadCounter++; |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 77 | } |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 78 | |
| 79 | time::steady_clock::TimePoint endTime = time::steady_clock::now(); |
| 80 | |
| 81 | time::duration<double, boost::nano> runDuration = endTime - startTime; |
| 82 | time::duration<double, boost::nano> perOperationTime = runDuration / nInsertions; |
| 83 | |
| 84 | std::cout << "nItem = " << nInsertions << std::endl; |
| 85 | std::cout << "Total running time = " |
| 86 | << time::duration_cast<time::duration<double> >(runDuration) |
| 87 | << std::endl; |
| 88 | std::cout << "Average per-operation time = " |
| 89 | << time::duration_cast<time::duration<double, boost::micro> >(perOperationTime) |
| 90 | << std::endl; |
| 91 | |
| 92 | if (previousResult > time::nanoseconds(1)) |
| 93 | std::cout << "Change compared to the previous: " |
| 94 | << (100.0 * perOperationTime / previousResult) << "%" << std::endl; |
| 95 | |
| 96 | std::cout << "\n=================================\n" << std::endl; |
| 97 | |
| 98 | previousResult = perOperationTime; |
| 99 | } |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 102 | } // namespace cs_smoketest |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 103 | } // namespace nfd |
| 104 | |
| 105 | int |
| 106 | main(int argc, char** argv) |
| 107 | { |
Junxiao Shi | 2e0db68 | 2014-11-27 21:22:27 -0700 | [diff] [blame^] | 108 | nfd::cs_smoketest::runStressTest(); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 109 | |
| 110 | return 0; |
| 111 | } |